65.9K
CodeProject is changing. Read more.
Home

How to find if a user is administrator or not

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.89/5 (8 votes)

Dec 5, 2011

CPOL
viewsIcon

23498

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);
}