c# - 为什么我的 WPF 应用程序中会出现 System.Security.AccessControl.PrivilegeNotHeldException?

标签 c# .net wpf security

我有一个简单的WPF应用程序,它试图查找给定用户所属的ActiveDirectory组。检索组的代码是:

public static HashSet<string> GetUserGroups(string userLogon)
{
    var groups = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
    var identity = new WindowsIdentity(userLogon);

    if (identity.Groups == null) { return groups; }

    var type = typeof(NTAccount);

    foreach (var group in identity.Groups)
    {
        groups.Add(group.Translate(type).ToString());
    }

    return groups;
}

但是,当我尝试在应用程序启动时运行此方法时,当该方法尝试创建new WindowsIdentity(userLogon)时,我会抛出以下异常:

System.Security.AccessControl.PrivilegeNotHeldException: 'The process does not possess the 'SeTcbPrivilege' privilege which is required for this operation.'

如果我在 Console 应用程序中运行代码,则不会发生这种情况。关于可能导致此问题的任何想法?

最佳答案

事实证明,我之所以看到此异常,是因为在公共(public)语言异常对话框中启用了所有公共(public)语言异常

此异常似乎是内部引发的。

关于c# - 为什么我的 WPF 应用程序中会出现 System.Security.AccessControl.PrivilegeNotHeldException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46588746/

相关文章:

c# - 当有人使用我的带有 "Open With"的程序时,我如何知道打开了什么文件?(C#)

c# - 使用 HttpWebRequest 向 servicestack 服务发送大型 (8mb) excel 文件时出错

c# - 方法未显示在生产中的堆栈跟踪中

c# - 为什么 Int32.ToString() 发出调用指令而不是 callvirt?

wpf - 网格中的滚动查看器

从 C++ DLL 调用时,带有参数的 C# 委托(delegate)回调会导致 AccessViolation

.net - 调试 ASP.NET session 变量

c# - 从泛型类中的接口(interface)继承

c# - 带有全选复选框的多选 ListView 。绑定(bind)属性上的数据触发

c# - WPF Mysql 数据列太长