c#在域环境下,获取 AD 用户信息。
Code
//域名例如:finehappy.com 域名一定要写对,否则获取不到数据
System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + domainName);
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=user)"); //user表示用户,group表示组
foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
}
Code
//域名例如:finehappy.com 域名一定要写对,否则获取不到数据
System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + domainName);
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=user)"); //user表示用户,group表示组
foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
}
DirectoryEntry()的参数要设置对,才行!
冯瑞涛