Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用用户名字符串创建WindowsIdentity,例如;“约翰多”;在C中#_C#_Windows Identity - Fatal编程技术网

C# 如何使用用户名字符串创建WindowsIdentity,例如;“约翰多”;在C中#

C# 如何使用用户名字符串创建WindowsIdentity,例如;“约翰多”;在C中#,c#,windows-identity,C#,Windows Identity,我有isAdministrator(字符串a),如下所示: public static bool IsAdministrator(String aString) { WindowsIdentity identity = new WindowsIdentity(a); WindowsPrincipal principal = new WindowsPrincipal(identity); return principal.IsInRole(WindowsBuiltInRol

我有
isAdministrator(字符串a)
,如下所示:

public static bool IsAdministrator(String aString)
{
    WindowsIdentity identity = new WindowsIdentity(a);
    WindowsPrincipal principal = new WindowsPrincipal(identity);
    return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
其中,
aString
是用户名。当我运行这个时,我意识到我需要一个UPN。这有什么关系吗


提前谢谢

单元测试需要这个吗?或者您正在尝试模拟已知的Windows帐户?我正在尝试模拟已知的Windows帐户