Calling IPrincipal.IsInRole on Windows 7

Posted by adrianbanks on Stack Overflow See other posts from Stack Overflow or by adrianbanks
Published on 2010-04-20T10:12:29Z Indexed on 2010/04/20 10:43 UTC
Read the original article Hit count: 564

Filed under:
|
|
|
|

We use NTLM auth in our application to determine whether a user can perform certain operations. We use the IPrincipal of their current Windows login (in WinForms applications), calling IsInRole to check for specific group memberships.

To check that a user is a local administrator on the machine, we use:

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
...
bool allowed = Thread.CurrentPrincipal.IsInRole(@"Builtin\Administrators")

This works if the current user is the Administrator user, or is another user that is a member of the Builtin\Administrators group.

In our testing on Windows 7, we have found that this no longer works as expected. The Administrator user still works fine, but any other user that is a member of the Builtin\Administrators group returns false for the IsInRole call.

What could be causing this difference? I have a gut feeling that a default setting has changed somewhere (possible in gpedit), but cannot find anything that looks like the culprit.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#