tags:

views:

522

answers:

3

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;
}
A: 

You could look at the full username, which is either <domain name>\<username> or <machine name>\<username> for domain and local accounts respectively. If the first part matches the domain name, it's obviously a domain account and the opposite holds true.

NYSystemsAnalyst
How do I programatically find out what the domain name is - how do I know that its a domain name and not that particular computers netbios name?
Ryan
+1  A: 

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

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

vIceBerg
Not exactly the same (infact that q is not to clear on exactly what is is asking - is it an ad environment/does the current user have an ad account/is current user logged on via ad etc) but helpful anyway - thanks
Ryan
+2  A: 

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)

Asher