C# 获取AD(域用户)的问题
在C#代码里有这么一段代码
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(); } }}