我有一个简单的
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
应用程序。你知道是什么导致了这一切吗?