如果确定当前用户是域或本地用户? [英] Determine if current user is a domain or local user?

查看:117
本文介绍了如果确定当前用户是域或本地用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来确定(.NET preferably)如果当前用户是域用户帐户或本地用户帐户?

的时间提前 - 我不不知道这是对,所以我不能只认准域\用户名v计算机\用户名运行的域名。

部分答案可能是确定从code中的域名或计算机名。

扩大对阿舍的回答一个code片段是

 私人布尔isCurrentUserLocalUser()
{
    返回Environment.MachineName == Environment.UserDomainName;
}
 

解决方案

您可以使用的 Environment.UserDomainName MSDN文档解释了这个属性的具体行为在各种情况下(域/本地帐户)

您可以使用这个属性与其他属性,如Environment.MachineName一起弄清楚什么是正在使用的用户帐户类型。

请注意该域帐户不一定是活动目录(可以是Novell公司的Netware的东西)

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

解决方案

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)

这篇关于如果确定当前用户是域或本地用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆