简体   繁体   中英

How to get 'Windows 10' user first & last name with offline DC

How to get user first name and last name in Windows 10 without connection to domain for specified (or at worst case logged in) account name? Machine was at least once connected to Domain Controller (Laptop).

I tried using UserPrincipal (which obviously throws PrincipalException with LDAPException inside). Also searched many threads (so far all are about case with DC connected).

Try this :

public static void GetUsers()  
{  
     SelectQuery sQuery = new SelectQuery(“Win32_UserAccount”,“Domain=’yourdomain’”);  

     try  
     {  
            ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(sQuery);  

            Console.WriteLine(“User Accounts\n”);  

            foreach (ManagementObject mObject in mSearcher.Get())  
            {  
                // Console.WriteLine(mObject[“Name”]);  
                // your logic
            }  
      }  
      catch (Exception ex)  
      {  
            Console.WriteLine(ex.Message);  
      }  


 } 

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