日期:2014-05-18 浏览次数:21101 次
DirectoryEntry entry = new DirectoryEntry(path);
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(objectClass=*)";
searcher.PropertiesToLoad.Clear();
SearchResultCollection searchResultCollection = searcher.FindAll();
foreach (SearchResult result in resultCollection)
{if ([color=#FF0000]result.Properties.Contains("samaccountname"))[/color] {
ResultPropertyValueCollection resultValue = result.Properties["samaccountname"];
if (resultValue != null && resultValue.Count > 0 && resultValue[0] != null)
{
userName = resultValue[0].ToString();
}
}
}