代码之家  ›  专栏  ›  技术社区  ›  MaYaN

为什么我得到了系统。安全访问控制。我的WPF应用程序中的PrivilegenothedException?

  •  2
  • MaYaN  · 技术社区  · 8 年前

    我有一个简单的 WPF

    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)

    系统安全访问控制。PrivilegenothedException:“过程 此操作。”

    不是,如果我在 Console 应用程序。你知道是什么导致了这一切吗?

    1 回复  |  直到 8 年前
        1
  •  3
  •   MaYaN    8 年前

    事实证明,由于启用了 All Common Language Exceptions Common Language Exception

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