System. environment. userdomainname: Why does not the current domainname be returned?

Source: Internet
Author: User
System. environment. userdomainname:

Obtain the network domain name associated with the current user.

There is a note below:

The value of this attribute is usually the host name, but may depend on the deployed application.ProgramSolution. The current user is the name specified in username.

Generally, if I add a domain, the current domain is returned. If not, the current machine name is returned.

Generally, this is correct. Sometimes, you will find that even if you are added to the domain, the returned machine name is used.

I found that there is a reason for this. userdomainname actually calls a lookupaccountname, and the explanation of this API is not clear.
Internal   Static   Extern   Bool Lookupaccountname ( String Machinename, String Accountname, Byte [] Sid, Ref   Int Sidlen, stringbuilder domainname, Ref   Int Domainnamelen, Out   Int Peuse );

About domainname,

Referenceddomainname
[Out] pointer to a buffer that determines es the name of the domain where the account name is found. for computers that are not joined to a domain, this buffer takes es the computer name. if this parameter is null, the function returns the required buffer size.

The server name is returned even if you are added to the domain.

Later we found the rule. If the domain user has the same user name on the local machine, the local machine name will be returned. In this case, it is okay to delete the local user.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.