Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if current user is a domain or local user?

Tags:

.net

Is there a way to determine (.NET preferably) if the current user is a domain user account or local user account?

Ahead of time - I don not know the domain name this is running on so I can't just look for DOMAIN\Username v COMPUTER\Username.

Part of the answer could be determining the DOMAIN or COMPUTER name from code.

[Edit] Expanding on Asher's answer a code fragment would be

private bool isCurrentUserLocalUser()
{
    return Environment.MachineName == Environment.UserDomainName;
}
like image 367
Ryan Avatar asked Nov 21 '08 20:11

Ryan


People also ask

What is domain user and local user?

Domain users are users that are entered into the domain users group on a domain controller. These domain users can be centrally managed at the server. Whereas the local users are the users created in the local system. In BPC, you can select users from either of them or in combination as well.

How do I know if my Windows account is local?

If your email address is displayed under your name, then you are using a Microsoft account. If you do not see any email address listed, but you see "Local Account" written right under your user name, then you are using an offline local account.


2 Answers

See that post and check if it's answering your question

how-do-i-detect-if-my-program-runs-in-an-active-directory-environment

like image 140
vIceBerg Avatar answered Oct 12 '22 11:10

vIceBerg


you can use Environment.UserDomainName the MSDN documentation explains the exact behavior of this property in each case (domain/local account)

You can use this property in conjunction with other properties like Environment.MachineName to figure out what is the type of the user account being used.

Note that domain account is not necessarily Active Directory (can be that Novell Netware stuff)

like image 25
Asher Avatar answered Oct 12 '22 10:10

Asher