简体   繁体   中英

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)

I have tried many methods using Windows Principle library & WMI Select commands. I keep getting Admministrator, Guest & some other VUSRNEIL-DELL. Neither of these 3 user accounts appear on the Logon screen. 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_LogonSessionWin32_LoggedOnUser类(其中Win32_LogonSession.LogonType ='2'),以获取当前登录的用户,然后可以将其与Win32_Account类相关联;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM