How to check if current user is in local admins security group

You can check whether current user belongs to Local Admin Group like this

1. Get reference to current WindowsIdentity

WindowsIdentity wi = WindowsIdentity.GetCurrent();

2. Create WindowsPrincipal using current windows identity

WindowsPrincipal wp = new WindowsPrincipal(wi);

3. Check if user is in "BUILTIN\Administrators" role

bool isAdmin = wp.IsInRole("BUILTIN\Administrators");

 

Published Wednesday, November 14, 2007 9:04 AM by Paki
Filed under: , ,

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Powered by Community Server (Commercial Edition), by Telligent Systems