System.Security.Principal.WindowsPrincipal.IsInRole Method

Determines whether the current principal belongs to the Windows user group with the specified name.


public virtual bool IsInRole (string role)


The name of the Windows user group for which to check membership.


true if the current principal is a member of the specified Windows user group; otherwise, false.


When testing for newly created role information, such as a new user or a new group, it is important to log out and log in to force the propagation of role information within the domain. Not doing so can cause the erload:System.Security.Principal.WindowsPrincipal.IsInRole test to return false. This method is not supported on Windows 98 or Windows Millennium Edition.

For performance reasons, the WindowsPrincipal.IsInRole(SecurityIdentifier) overload is recommended as the preferable overload for determining the user's role.


In Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. When you attempt to perform a task that requires administrative privileges, you can dynamically elevate your role by using the Consent dialog box. The code that executes the erload:System.Security.Principal.WindowsPrincipal.IsInRole method does not display the Consent dialog box. The code returns false if you are in the standard user role, even if you are in the Built-in Administrators group. You can elevate your privileges before you execute the code by right-clicking the application icon and indicating that you want to run as an administrator.

For built-in roles, the role string should be in the form "BUILTIN\RoleNameHere". For example, to test for membership in the Windows administrator role, the string representing the role should be "BUILTIN\Administrators". Note that the backslash might need to be escaped. The following table lists the built-in roles.


The spelling for the BUILTIN roles in string format differs from the spelling used in the System.Security.Principal.WindowsBuiltInRole enumeration. For example, the spelling for an administrator in the enumeration is "Administrator", not "Administrators". When using this overload, use the spelling for the role from the following table.

BUILTIN\Account Operators
BUILTIN\Server Operators
BUILTIN\Print Operators
BUILTIN\Backup Operators

For machine-specific roles, the role string should be in the form "MachineName\RoleNameHere".

For domain-specific roles, the role string should be in the form "DomainName\RoleNameHere"; for example, "SomeDomain\Domain Users".


In the .NET Framework version 1.0, the role parameter is case-sensitive. In the .NET Framework version 1.1 and later, the role parameter is case-insensitive.


Namespace: System.Security.Principal
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0,,