List Of Domains
Hi,
I am trying to list out the domains on the server using System.DirectoryServices. It gives domains, but list contains only one domain name. Our server has more that 3
domains and subdomains.
The code which i am using is as follows.
private StringCollection GetDomainList()
{
StringCollection domainList = new StringCollection();
try
{
DirectoryEntry en = new DirectoryEntry("WinNT://");
// Search for objectCategory type "Domain"
DirectorySearcher srch = new DirectorySearcher("objectCategory=Domain");
SearchResultCollection coll = srch.FindAll();
// Enumerate over each returned domain.
foreach (SearchResult rs in coll)
{
ResultPropertyCollection resultPropColl = rs.Properties;
foreach( object domainName in resultPropColl["name"])
{
domainList.Add(domainName.ToString());
}
}
}
catch (Exception ex)
{
Trace.Write(ex.Message);
}
return domainList;
}
Is it the correct way to list the domains? It is giving only the domain name in which i am a user and i log in with this user. This domain has subdomains and also along with this other domains are also there.
Can you please help out?
Thanx
Iftach
Replies
Know the answer? Post it — somebody with the same question will find it here.