Check if user has administartor rights
In numerous cases it is essential to know if the user has administrator rights or not. A good example for this would be when we want to decide if we want to write a value in
HKEY_LOCAL_MACHINE which requires administrator rights or
HKEY_CURRENT_USER which doesn’t.
The following method will return true if the application is running under administration rights or false if its not.
public static bool IsUserAdministrator()
WindowsIdentity user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
Leave a Reply