Determine if current user is a domain or local user?

匿名 (未验证) 提交于 2019-12-03 00:50:01

问题:

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

回答1:

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)



回答2:

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

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



回答3:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!