I m试图获得Windowslogin dialog(域网缩小)中所有可使用的领域。
我先尝试了以下法典,但只是回到了我所gged的领域。 我失踪了吗?
StringCollection domainList = new StringCollection();
try
{
DirectoryEntry en = new DirectoryEntry();
// Search for objectCategory type "Domain"
DirectorySearcher srch = new DirectorySearcher(en, "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;