小编Dar*_*oar的帖子

c# 如何检查当前用户是否在管理员组中

我已阅读相关的 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。

我缺少什么?

谢谢。

.net c#

4
推荐指数
1
解决办法
3947
查看次数

标签 统计

.net ×1

c# ×1