获取域用户信息 [英] Get Domain User information
本文介绍了获取域用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取Windows域的所有当前用户名?
How can i get all current usernames of a windows domain?
if (!String.IsNullOrEmpty(domainName))
{
DirectoryEntry myDirectoryEntry = new DirectoryEntry(String.Format("LDAP://{0}", domainName));
DirectorySearcher mySearcher = new DirectorySearcher(myDirectoryEntry);
SortOption mySort = new SortOption("sn", SortDirection.Ascending);
mySearcher.Filter = ("(objectCategory=person)");
mySearcher.Sort = mySort;
foreach (SearchResult resEnt in mySearcher.FindAll())
{
if ( System.Text.RegularExpressions.Regex.IsMatch(resEnt.Properties["displayName"][0].ToString(), " |admin|test|service|system|[$]", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
int space = resEnt.Properties["displayName"][0].ToString().IndexOf(" ");
string formattedName = String.Format("{0}",
resEnt.Properties["displayName"][0].ToString().Substring(space).PadRight(25), );
userList.Add(formattedName);
}
}
}
我尝试了此代码,但userList获得了域中所有注册的用户名.我想过滤当前登录的用户
i tried this code but userList gets all registered Usernames in the Domain. I want to filter current logged in users
推荐答案
,System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { int space = resEnt.Properties ["displayName"] [0] .ToString().IndexOf("); 字符串formattedName = String.Format("{0}", resEnt.Properties ["displayName"] [0] .ToString().Substring(space).PadRight(25),); userList.Add(formattedName); } } }
", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { int space = resEnt.Properties["displayName"][0].ToString().IndexOf(" "); string formattedName = String.Format("{0}", resEnt.Properties["displayName"][0].ToString().Substring(space).PadRight(25), ); userList.Add(formattedName); } } }
我尝试了此代码,但userList获得了域中所有注册的用户名.我要过滤当前登录的用户
i tried this code but userList gets all registered Usernames in the Domain. I want to filter current logged in users
查看方法:(几乎)通过C# [ ^ ],也许您可以在这里找到一些好的答案.
Look at Howto: (Almost) Everything In Active Directory via C#[^], perhaps you can find some good answers there.
这篇关于获取域用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文