Share via


WindowsBuiltInRole Enum

Definisi

Menentukan peran umum yang akan digunakan dengan IsInRole(String).

public enum class WindowsBuiltInRole
public enum WindowsBuiltInRole
[System.Serializable]
public enum WindowsBuiltInRole
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum WindowsBuiltInRole
type WindowsBuiltInRole = 
[<System.Serializable>]
type WindowsBuiltInRole = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type WindowsBuiltInRole = 
Public Enum WindowsBuiltInRole
Warisan
WindowsBuiltInRole
Atribut

Bidang

AccountOperator 548

Operator akun mengelola akun pengguna di komputer atau domain.

Administrator 544

Administrator memiliki akses lengkap dan tidak terbatas ke komputer atau domain.

BackupOperator 551

Operator Cadangan dapat mengambil alih pembatasan keamanan untuk tujuan tunggal mencadangkan atau memulihkan file.

Guest 546

Tamu lebih terbatas daripada pengguna.

PowerUser 547

Pengguna daya memiliki sebagian besar izin administratif dengan beberapa batasan. Dengan demikian, pengguna daya dapat menjalankan aplikasi warisan, selain aplikasi bersertifikat.

PrintOperator 550

Operator cetak dapat mengendalikan printer.

Replicator 552

Replikator mendukung replikasi file di domain.

SystemOperator 549

Operator sistem mengelola komputer tertentu.

User 545

Pengguna dicegah membuat perubahan di seluruh sistem yang tidak disengaja atau disengaja. Dengan demikian, pengguna dapat menjalankan aplikasi bersertifikat, tetapi bukan sebagian besar aplikasi warisan.

Contoh

Contoh berikut menunjukkan penggunaan WindowsBuiltInRole enumerasi.

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

      myDomain->SetPrincipalPolicy( PrincipalPolicy::WindowsPrincipal );
      WindowsPrincipal^ myPrincipal = dynamic_cast<WindowsPrincipal^>(Thread::CurrentPrincipal);

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

      Array^ wbirFields = Enum::GetValues( WindowsBuiltInRole::typeid );

      for each ( Object^ roleName in wbirFields )
      {
         try
         {
            Console::WriteLine( "{0}? {1}.", roleName,
               myPrincipal->IsInRole(  *dynamic_cast<WindowsBuiltInRole^>(roleName) ) );
         }
         catch ( Exception^ ) 
         {
            Console::WriteLine( "{0}: Could not obtain role for this RID.",
               roleName );
         }
      }
   }
using System;
using System.Threading;
using System.Security.Permissions;
using System.Security.Principal;

class SecurityPrincipalDemo
{
    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
            {
                // Cast the role name to a RID represented by the WindowsBuildInRole value.
                Console.WriteLine("{0}? {1}.", roleName,
                    myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
                Console.WriteLine("The RID for this role is: " + ((int)roleName).ToString());
            }
            catch (Exception)
            {
                Console.WriteLine("{0}: Could not obtain role for this RID.",
                    roleName);
            }
        }
        // Get the role using the string value of the role.
        Console.WriteLine("{0}? {1}.", "Administrators",
            myPrincipal.IsInRole("BUILTIN\\" + "Administrators"));
        Console.WriteLine("{0}? {1}.", "Users",
            myPrincipal.IsInRole("BUILTIN\\" + "Users"));
        // Get the role using the WindowsBuiltInRole enumeration value.
        Console.WriteLine("{0}? {1}.", WindowsBuiltInRole.Administrator,
           myPrincipal.IsInRole(WindowsBuiltInRole.Administrator));
        // Get the role using the WellKnownSidType.
        SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
        Console.WriteLine("WellKnownSidType BuiltinAdministratorsSid  {0}? {1}.", sid.Value, myPrincipal.IsInRole(sid));
    }

    public static void Main()
    {
        DemonstrateWindowsBuiltInRoleEnum();
    }
}
Imports System.Threading
Imports System.Security.Permissions
Imports System.Security.Principal

Class SecurityPrincipalDemo

    Public Shared Sub DemonstrateWindowsBuiltInRoleEnum()
        Dim myDomain As AppDomain = Thread.GetDomain()

        myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
        Dim myPrincipal As WindowsPrincipal = CType(Thread.CurrentPrincipal, WindowsPrincipal)
        Console.WriteLine("{0} belongs to: ", myPrincipal.Identity.Name.ToString())
        Dim wbirFields As Array = [Enum].GetValues(GetType(WindowsBuiltInRole))
        Dim roleName As Object
        For Each roleName In wbirFields
            Try
                ' Cast the role name to a RID represented by the WindowsBuildInRole value.
                Console.WriteLine("{0}? {1}.", roleName, myPrincipal.IsInRole(CType(roleName, WindowsBuiltInRole)))
                Console.WriteLine("The RID for this role is: " + Fix(roleName).ToString())

            Catch
                Console.WriteLine("{0}: Could not obtain role for this RID.", roleName)
            End Try
        Next roleName
        ' Get the role using the string value of the role.
        Console.WriteLine("{0}? {1}.", "Administrators", myPrincipal.IsInRole("BUILTIN\" + "Administrators"))
        Console.WriteLine("{0}? {1}.", "Users", myPrincipal.IsInRole("BUILTIN\" + "Users"))
        ' Get the role using the WindowsBuiltInRole enumeration value.
        Console.WriteLine("{0}? {1}.", WindowsBuiltInRole.Administrator, myPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
        ' Get the role using the WellKnownSidType.
        Dim sid As New SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, Nothing)
        Console.WriteLine("WellKnownSidType BuiltinAdministratorsSid  {0}? {1}.", sid.Value, myPrincipal.IsInRole(sid))

    End Sub

    Public Shared Sub Main()
        DemonstrateWindowsBuiltInRoleEnum()

    End Sub
End Class

Keterangan

Peran ini mewakili grup Windows lokal yang umum untuk sebagian besar penginstalan Windows NT, Windows 2000 dan Windows XP.

Catatan

Di Windows Vista, Kontrol Akun Pengguna (UAC) menentukan hak istimewa pengguna. Jika Anda adalah anggota grup Administrator Bawaan, Anda diberi dua token akses run-time: token akses pengguna standar dan token akses administrator. Secara default, Anda berada dalam peran pengguna standar. Saat Anda mencoba melakukan tugas yang memerlukan hak istimewa administratif, Anda dapat meningkatkan peran Anda secara dinamis dengan menggunakan kotak dialog Persetujuan. Kode yang menjalankan IsInRole metode tidak menampilkan kotak dialog Persetujuan. Kode mengembalikan false jika Anda berada dalam peran pengguna standar, bahkan jika Anda berada di grup Administrator Bawaan. Anda dapat meningkatkan hak istimewa sebelum menjalankan kode dengan mengklik kanan ikon aplikasi dan menunjukkan bahwa Anda ingin menjalankan sebagai administrator.

Berlaku untuk