简体   繁体   中英

What is the difference between these two ways of obtaining Domain names?

What is the difference between these two statements.

    System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName;

and

    Environment.UserName;

Is there any way to retrieve the machine domain without using System.DirectoryServices ?

I hope this helps:

From: https://msdn.microsoft.com/en-us/library/system.environment.userdomainname(v=vs.110).aspx

The UserName property wraps a call to the Windows GetUserName function. The domain account credentials for a user are formatted as the user's domain name, the '\\' character, and user name. Use the UserDomainName property to obtain the user's domain name and the UserName property to obtain the user name.

The Environment.UserName uses GetUserName

Environment.UserDomainName

Will get the User's domain name.

https://msdn.microsoft.com/en-us/library/system.environment.userdomainname(v=vs.110).aspx

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