0

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,

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by LizR
0

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());
	}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.