C# 获取 域(AD) 用户信息
2009-01-09 12:57 闫妍 阅读(612) 评论(0) 编辑 收藏 举报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()的参数要设置对,才行!