I have a simple WPF application which is trying to find the ActiveDirectory groups a given user is a member of. The code for retrieving the groups is:
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;
}
However when I try running this at the startup of the app, I get the following exception thrown when the method tries to create the new WindowsIdentity(userLogon):
System.Security.AccessControl.PrivilegeNotHeldException: 'The process does not possess the 'SeTcbPrivilege' privilege which is required for this operation.'
Not this does not happen if I run the code in a Console app. Any ideas on what could be causing this?