我已阅读相关的 Stack Overflow 问题并尝试了以下代码:
WindowsIdentity identity = WindowsIdentity.GetCurrent();
if (null != identity)
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
return false;
Run Code Online (Sandbox Code Playgroud)
即使我手动确认当前用户是本地内置管理员组的成员,它也不会返回 true。
我缺少什么?
谢谢。