Hi there,
I am developing a desktop application that has a form that shows Domain on a System/ Network.The System.Environment.UserDomainName only tells the current user's domain. I want to see all the available domains and all the users under those doamain.
I want to know how can I read Domains in C#.
Regards,

I have used this in the past to query the domains. To get users, you will use the same concept of directory searcher, I think objectCategory=User. Make sure you have rights to query when using the directory searcher.

ArrayList domains = new ArrayList();

DirectoryEntry dirEntry = new DirectoryEntry("LDAP://");

DirectorySearcher dirSearcher = new DirectorySearcher("objectCategory=Domain");
SearchResultCollection coll = srch.FindAll();

foreach (SearchResult sr in coll)
{
	ResultPropertyCollection resultPropColl = sr.Properties;
	foreach( object domain in resultPropColl["name"])
	{
		domains.Add(domain.ToString());
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.