How to find if a user is administrator or not






4.89/5 (8 votes)
Find if a user is administrator or not.
This code tells you if the user who is logged in is an administrator or not.
using System.Security.Principal;
bool IsAnAdministrator ()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal (identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}