[英]How can I get a list of Active Directory Users (Only the Users that appear in the windows Logon Screen)
How can I get a list of Active Directory Users (Only the Users that appear in the windows Logon Screen) 如何获取Active Directory用户列表(仅Windows登录屏幕中显示的用户)
I have tried many methods using Windows Principle library & WMI Select commands. 我已经尝试过使用Windows Principle库和WMI Select命令的许多方法。 I keep getting Admministrator, Guest & some other VUSRNEIL-DELL.
我不断得到Admministrator,Guest和其他VUSRNEIL-DELL的支持。 Neither of these 3 user accounts appear on the Logon screen.
这3个用户帐户均未出现在“登录”屏幕上。 How can I Deifferientiate between these user types?
如何区分这些用户类型?
//Add a reference on System.DirectoryServices.dll
using System.DirectoryServices;
//Connect to your LDAP
DirectoryEntry Ldap = new DirectoryEntry("LDAP://ADName", "Login", "Password");
DirectorySearcher searcher = new DirectorySearcher(Ldap);
//specify that you search user only by filtering AD objects
searcher.Filter = "(objectClass=user)";
//Loop on each users
foreach( SearchResult result in searcher.FindAll() )
{
// On récupère l'entrée trouvée lors de la recherche
DirectoryEntry DirEntry = result.GetDirectoryEntry();
//On peut maintenant afficher les informations désirées
Console.WriteLine("Login : " + DirEntry.Properties["SAMAccountName"].Value);
Console.WriteLine("FirstName: " + DirEntry.Properties["sn"].Value);
Console.WriteLine("LastName: " + DirEntry.Properties["givenName"].Value);
Console.WriteLine("Email : " + DirEntry.Properties["mail"].Value);
Console.WriteLine("Phone: " + DirEntry.Properties["TelephoneNumber"].Value);
Console.WriteLine("Description : " + DirEntry.Properties["description"].Value);
Console.WriteLine("-------------------");
}
检查Win32_LogonSession和Win32_LoggedOnUser类(其中Win32_LogonSession.LogonType ='2'),以获取当前登录的用户,然后可以将其与Win32_Account类相关联;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.