1 out of 1 rated this helpful - Rate this topic

WindowsBuiltInRole Enumeration

Specifies common roles to be used with IsInRole.

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

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum WindowsBuiltInRole
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum WindowsBuiltInRole
SerializableAttribute 
ComVisibleAttribute(true) 
public enum WindowsBuiltInRole
  Member name Description
AccountOperator Account operators manage the user accounts on a computer or domain. 
Administrator Administrators have complete and unrestricted access to the computer or domain. 
BackupOperator Backup operators can override security restrictions for the sole purpose of backing up or restoring files. 
Guest Guests are more restricted than users. 
PowerUser Power users possess most administrative permissions with some restrictions. Thus, power users can run legacy applications, in addition to certified applications. 
PrintOperator Print operators can take control of a printer. 
Replicator Replicators support file replication in a domain. 
SystemOperator System operators manage a particular computer. 
User Users are prevented from making accidental or intentional system-wide changes. Thus, users can run certified applications, but not most legacy applications. 

These roles represent the local Windows groups common to most installations of Windows NT, Windows 2000 and Windows XP.

The following example shows the use of the WindowsBuiltInRole enumeration.


public static void DemonstrateWindowsBuiltInRoleEnum()
{
    AppDomain myDomain = Thread.GetDomain();

    myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
    WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;


    Console.WriteLine("{0} belongs to: ", myPrincipal.Identity.Name.ToString());

    Array wbirFields = Enum.GetValues(typeof(WindowsBuiltInRole));

    foreach (object roleName in wbirFields)
    {
        try
        {
            Console.WriteLine("{0}? {1}.", roleName,
                myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
        } 
        catch (Exception)
        {
            Console.WriteLine("{0}: Could not obtain role for this RID.",
                roleName);
        }
    }        

}


public static void DemonstrateWindowsBuiltInRoleEnum()
{
    AppDomain myDomain = Thread.GetDomain();

    myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

    WindowsPrincipal myPrincipal = ((WindowsPrincipal)
        (Thread.get_CurrentPrincipal()));

    Console.WriteLine("{0} belongs to: ",
        myPrincipal.get_Identity().get_Name().ToString());

    Array wbirFields = Enum.GetValues(WindowsBuiltInRole.class.ToType());

    for (int iCtr = 0; iCtr < wbirFields.get_Count(); iCtr++) {
        Object roleName = wbirFields.get_Item(iCtr);
        try {
            Console.WriteLine("{0}? {1}.", roleName, 
            System.Convert.ToString(myPrincipal.
            IsInRole(((WindowsBuiltInRole)(roleName)))));
        }
        catch (System.Exception exp) {
            Console.WriteLine(
                "{0}: Could not obtain role for this RID.", roleName);
        }
    }
} //DemonstrateWindowsBuiltInRoleEnum

Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ