RegistryAccessRule 클래스

정의

사용자 또는 그룹에 대해 허용 또는 거부된 액세스 권한 집합을 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class RegistryAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class RegistryAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class RegistryAccessRule : System.Security.AccessControl.AccessRule
type RegistryAccessRule = class
    inherit AccessRule
[<System.Security.SecurityCritical>]
type RegistryAccessRule = class
    inherit AccessRule
Public NotInheritable Class RegistryAccessRule
Inherits AccessRule
상속
RegistryAccessRule
특성

예제

다음 코드 예제에서는 상속 및 전파를 사용하는 액세스 규칙을 보여 줍니다. 이 예제에서는 개체를 RegistrySecurity 만든 다음 플래그가 있는 ContainerInherit 두 개의 규칙을 만들고 추가합니다. 첫 번째 규칙에는 전파 플래그가 없고 두 번째 규칙에는 NoPropagateInherit 전파 플래그가 없습니다 InheritOnly.

프로그램은 개체에 규칙을 RegistrySecurity 표시한 다음 개체를 사용하여 하위 키를 만듭니다. 프로그램은 자식 하위 키와 손자 하위 키를 만든 다음 각 하위 키에 대한 보안을 표시합니다. 마지막으로 프로그램에서 테스트 키를 삭제합니다.


using System;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Security;
using Microsoft.Win32;

public class Example
{
    public static void Main()
    {
        const string TestKey = "TestKey3927";
        RegistryKey cu = Registry.CurrentUser;

        string user = Environment.UserDomainName + 
            "\\" + Environment.UserName;

        // Create a security object that grants no access.
        RegistrySecurity mSec = new RegistrySecurity();

        // Add a rule that grants the current user the right
        // to read and enumerate the name/value pairs in a key, 
        // to read its access and audit rules, to enumerate
        // its subkeys, to create subkeys, and to delete the key. 
        // The rule is inherited by all contained subkeys.
        //
        RegistryAccessRule rule = new RegistryAccessRule(user, 
           RegistryRights.ReadKey | RegistryRights.WriteKey 
               | RegistryRights.Delete, 
           InheritanceFlags.ContainerInherit, 
           PropagationFlags.None, 
           AccessControlType.Allow
        );
        mSec.AddAccessRule(rule);

        // Add a rule that allows the current user the right
        // right to set the name/value pairs in a key. 
        // This rule is inherited by contained subkeys, but
        // propagation flags limit it to immediate child 
        // subkeys.
        rule = new RegistryAccessRule(user, 
            RegistryRights.ChangePermissions, 
            InheritanceFlags.ContainerInherit, 
            PropagationFlags.InheritOnly | 
                PropagationFlags.NoPropagateInherit, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        // Display the rules in the security object.
        ShowSecurity(mSec);

        // Create the test key using the security object.
        //
        RegistryKey rk = cu.CreateSubKey(TestKey, 
            RegistryKeyPermissionCheck.ReadWriteSubTree, mSec);

        // Create a child subkey and a grandchild subkey, 
        // without security.
        RegistryKey rkChild = rk.CreateSubKey("ChildKey", 
            RegistryKeyPermissionCheck.ReadWriteSubTree);
        RegistryKey rkGrandChild = 
            rkChild.CreateSubKey("GrandChildKey", 
                RegistryKeyPermissionCheck.ReadWriteSubTree);

        Show(rk);
        Show(rkChild);
        Show(rkGrandChild);

        rkGrandChild.Close();
        rkChild.Close();
        rk.Close();

        cu.DeleteSubKeyTree(TestKey);
    }

    private static void Show(RegistryKey rk)
    {
        Console.WriteLine(rk.Name);
        ShowSecurity(rk.GetAccessControl());
    }

    private static void ShowSecurity(RegistrySecurity security)
    {
        Console.WriteLine("\r\nCurrent access rules:\r\n");

        foreach( RegistryAccessRule ar in security.GetAccessRules(true, true, typeof(NTAccount)) )
        {

            Console.WriteLine("        User: {0}", ar.IdentityReference);
            Console.WriteLine("        Type: {0}", ar.AccessControlType);
            Console.WriteLine("      Rights: {0}", ar.RegistryRights);
            Console.WriteLine(" Inheritance: {0}", ar.InheritanceFlags);
            Console.WriteLine(" Propagation: {0}", ar.PropagationFlags);
            Console.WriteLine("   Inherited? {0}", ar.IsInherited);
            Console.WriteLine();
        }
    }
}

/* This code example produces output similar to following:

Current access rules:

        User: TestDomain\TestUser
        Type: Allow
      Rights: SetValue, CreateSubKey, Delete, ReadKey
 Inheritance: ContainerInherit
 Propagation: None
   Inherited? False

        User: TestDomain\TestUser
        Type: Allow
      Rights: ChangePermissions
 Inheritance: ContainerInherit
 Propagation: NoPropagateInherit, InheritOnly
   Inherited? False

HKEY_CURRENT_USER\TestKey3927

Current access rules:

        User: TestDomain\TestUser
        Type: Allow
      Rights: SetValue, CreateSubKey, Delete, ReadKey
 Inheritance: ContainerInherit
 Propagation: None
   Inherited? False

        User: TestDomain\TestUser
        Type: Allow
      Rights: ChangePermissions
 Inheritance: ContainerInherit
 Propagation: NoPropagateInherit, InheritOnly
   Inherited? False

HKEY_CURRENT_USER\TestKey3927\ChildKey

Current access rules:

        User: TestDomain\TestUser
        Type: Allow
      Rights: SetValue, CreateSubKey, Delete, ReadKey
 Inheritance: ContainerInherit
 Propagation: None
   Inherited? True

        User: TestDomain\TestUser
        Type: Allow
      Rights: ChangePermissions
 Inheritance: None
 Propagation: None
   Inherited? True

HKEY_CURRENT_USER\TestKey3927\ChildKey\GrandChildKey

Current access rules:

        User: TestDomain\TestUser
        Type: Allow
      Rights: SetValue, CreateSubKey, Delete, ReadKey
 Inheritance: ContainerInherit
 Propagation: None
   Inherited? True
 */
Option Explicit
Imports System.Security.AccessControl
Imports System.Security.Principal
Imports System.Security
Imports Microsoft.Win32

Public Class Example

    Public Shared Sub Main()

        Const TestKey As String = "TestKey3927"
        Dim cu As RegistryKey = Registry.CurrentUser

        Dim user As String = Environment.UserDomainName _ 
            & "\" & Environment.UserName

        ' Create a security object that grants no access.
        Dim mSec As New RegistrySecurity()

        ' Add a rule that grants the current user the right
        ' to read and enumerate the name/value pairs in a key, 
        ' to read its access and audit rules, to enumerate
        ' its subkeys, to create subkeys, and to delete the key. 
        ' The rule is inherited by all contained subkeys.
        '
        Dim rule As New RegistryAccessRule(user, _
            RegistryRights.ReadKey Or RegistryRights.WriteKey _
                Or RegistryRights.Delete, _
            InheritanceFlags.ContainerInherit, _
            PropagationFlags.None, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Add a rule that allows the current user the right
        ' right to set the name/value pairs in a key. 
        ' This rule is inherited by contained subkeys, but
        ' propagation flags limit it to immediate child 
        ' subkeys.
        rule = New RegistryAccessRule(user, _
            RegistryRights.ChangePermissions, _
            InheritanceFlags.ContainerInherit, _
            PropagationFlags.InheritOnly Or PropagationFlags.NoPropagateInherit, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Display the rules in the security object.
        ShowSecurity(mSec)

        ' Create the test key using the security object.
        '
        Dim rk As RegistryKey = cu.CreateSubKey(TestKey, _
            RegistryKeyPermissionCheck.ReadWriteSubTree, _
            mSec)

        ' Create a child subkey and a grandchild subkey, 
        ' without security.
        Dim rkChild As RegistryKey= rk.CreateSubKey("ChildKey", _
            RegistryKeyPermissionCheck.ReadWriteSubTree)
        Dim rkGrandChild As RegistryKey = _
            rkChild.CreateSubKey("GrandChildKey", _
                RegistryKeyPermissionCheck.ReadWriteSubTree)

        Show(rk)
        Show(rkChild)
        Show(rkGrandChild)

        rkGrandChild.Close()
        rkChild.Close()
        rk.Close()

        cu.DeleteSubKeyTree(TestKey)
    End Sub 

    Private Shared Sub Show(ByVal rk As RegistryKey)
        Console.WriteLine(rk.Name)            
        ShowSecurity(rk.GetAccessControl())
    End Sub

    Private Shared Sub ShowSecurity(ByVal security As RegistrySecurity)
        Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf)

        For Each ar As RegistryAccessRule In _
            security.GetAccessRules(True, True, GetType(NTAccount))

            Console.WriteLine("        User: {0}", ar.IdentityReference)
            Console.WriteLine("        Type: {0}", ar.AccessControlType)
            Console.WriteLine("      Rights: {0}", ar.RegistryRights)
            Console.WriteLine(" Inheritance: {0}", ar.InheritanceFlags)
            Console.WriteLine(" Propagation: {0}", ar.PropagationFlags)
            Console.WriteLine("   Inherited? {0}", ar.IsInherited)
            Console.WriteLine()
        Next

    End Sub
End Class 

'This code example produces output similar to following:
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: SetValue, CreateSubKey, Delete, ReadKey
' Inheritance: ContainerInherit
' Propagation: None
'   Inherited? False
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: ChangePermissions
' Inheritance: ContainerInherit
' Propagation: NoPropagateInherit, InheritOnly
'   Inherited? False
'
'HKEY_CURRENT_USER\TestKey3927
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: SetValue, CreateSubKey, Delete, ReadKey
' Inheritance: ContainerInherit
' Propagation: None
'   Inherited? False
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: ChangePermissions
' Inheritance: ContainerInherit
' Propagation: NoPropagateInherit, InheritOnly
'   Inherited? False
'
'HKEY_CURRENT_USER\TestKey3927\ChildKey
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: SetValue, CreateSubKey, Delete, ReadKey
' Inheritance: ContainerInherit
' Propagation: None
'   Inherited? True
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: ChangePermissions
' Inheritance: None
' Propagation: None
'   Inherited? True
'
'HKEY_CURRENT_USER\TestKey3927\ChildKey\GrandChildKey
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: SetValue, CreateSubKey, Delete, ReadKey
' Inheritance: ContainerInherit
' Propagation: None
'   Inherited? True

설명

RegistryAccessRule 클래스는 .NET Framework 레지스트리 키에서 Windows 액세스 제어 보안을 관리하기 위해 제공하는 클래스 집합 중 하나입니다. 이러한 클래스의 개요와 기본 Windows 액세스 제어 구조와의 관계는 다음을 참조하세요RegistrySecurity.

참고

Windows 액세스 제어 보안은 레지스트리 키에만 적용할 수 있습니다. 키에 저장된 개별 키/값 쌍에는 적용할 수 없습니다.

레지스트리 키에 현재 적용된 규칙 목록을 가져오려면 메서드를 사용하여 RegistryKey.GetAccessControl 개체를 RegistrySecurity 가져온 다음 해당 메서드를 GetAccessRules 사용하여 개체 컬렉션을 RegistryAccessRule 가져옵니다.

RegistryAccessRule 개체는 기본 DACL(임의 제어 액세스 목록)의 액세스 제어 항목과 일대일로 매핑되지 않습니다. 레지스트리 키에 대한 모든 액세스 규칙 집합을 가져오면 집합에는 현재 모든 액세스 제어 항목을 표현하는 데 필요한 최소 규칙 수가 포함됩니다.

참고

규칙을 적용하고 제거하면 기본 액세스 제어 항목이 변경됩니다. 가능한 경우 규칙의 정보가 병합되어 가장 적은 수의 액세스 제어 항목을 유지 관리합니다. 따라서 현재 규칙 목록을 읽을 때 추가한 모든 규칙 목록과 정확히 일치하지 않을 수 있습니다.

개체를 사용하여 RegistryAccessRule 사용자 또는 그룹을 허용하거나 거부할 액세스 권한을 지정합니다. 개체는 RegistryAccessRule 항상 허용된 액세스 또는 거부된 액세스를 나타내며 둘 다 표시하지 않습니다.

레지스트리 키에 규칙을 적용하려면 메서드를 RegistryKey.GetAccessControl 사용하여 개체를 RegistrySecurity 가져옵니다. 해당 메서드를 사용하여 개체를 RegistrySecurity 수정하여 규칙을 추가한 다음, 이 메서드를 RegistryKey.SetAccessControl 사용하여 보안 개체를 다시 연결합니다.

중요

변경된 보안 개체를 RegistrySecurity 레지스트리 키에 할당하는 메서드를 호출 RegistryKey.SetAccessControl 할 때까지 개체를 변경해도 레지스트리 키의 액세스 수준에는 영향을 미치지 않습니다.

RegistryAccessRule 개체는 변경할 수 없습니다. 레지스트리 키에 대한 보안은 규칙을 추가하거나 제거하는 클래스의 RegistrySecurity 메서드를 사용하여 수정됩니다. 이렇게 하면 기본 액세스 제어 항목이 수정됩니다.

생성자

RegistryAccessRule(IdentityReference, RegistryRights, AccessControlType)

RegistryAccessRule 클래스의 새 인스턴스를 초기화하여 규칙을 적용할 사용자 또는 그룹, 액세스 권한 및 지정된 액세스 권한의 허용 또는 거부를 지정합니다.

RegistryAccessRule(IdentityReference, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType)

규칙을 적용할 사용자 또는 그룹, 액세스 권한, 상속 플래그, 전파 플래그 및 지정된 액세스 권한의 허용 여부를 지정하여 RegistryAccessRule 클래스의 새 인스턴스를 초기화합니다.

RegistryAccessRule(String, RegistryRights, AccessControlType)

RegistryAccessRule 클래스의 새 인스턴스를 초기화하여 규칙을 적용할 사용자 또는 그룹의 이름, 액세스 권한 및 지정된 액세스 권한의 허용 또는 거부 여부를 지정합니다.

RegistryAccessRule(String, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType)

RegistryAccessRule 클래스의 새 인스턴스를 초기화하여 규칙을 적용할 사용자 또는 그룹의 이름, 액세스 권한, 상속 플래그, 전파 플래그 및 지정된 액세스 권한의 허용 또는 거부 여부를 지정합니다.

속성

AccessControlType

AccessControlType 개체와 관련된 AccessRule 값을 가져옵니다.

(다음에서 상속됨 AccessRule)
AccessMask

이 규칙의 액세스 마스크를 가져옵니다.

(다음에서 상속됨 AuthorizationRule)
IdentityReference

이 규칙이 적용되는 IdentityReference를 가져옵니다.

(다음에서 상속됨 AuthorizationRule)
InheritanceFlags

이 규칙이 자식 개체에서 상속되는 방식을 결정하는 플래그 값을 가져옵니다.

(다음에서 상속됨 AuthorizationRule)
IsInherited

이 규칙이 명시적으로 설정되는지 아니면 부모 컨테이너 개체에서 상속되는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 AuthorizationRule)
PropagationFlags

이 규칙의 상속이 자식 개체에 전파되는 방법을 결정하는 전파 플래그의 값을 가져옵니다. 이 속성은 InheritanceFlags 열거형의 값이 None이 아닐 때만 중요합니다.

(다음에서 상속됨 AuthorizationRule)
RegistryRights

액세스 규칙에 의해 허용 또는 거부된 권한을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상