我有一个简单的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/