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帐户