RegistrySecurity.RemoveAccessRuleSpecific(RegistryAccessRule) 메서드

정의

지정한 규칙과 정확히 일치하는 액세스 제어 규칙을 검색하여 제거합니다.

public:
 void RemoveAccessRuleSpecific(System::Security::AccessControl::RegistryAccessRule ^ rule);
public void RemoveAccessRuleSpecific (System.Security.AccessControl.RegistryAccessRule rule);
override this.RemoveAccessRuleSpecific : System.Security.AccessControl.RegistryAccessRule -> unit
Public Sub RemoveAccessRuleSpecific (rule As RegistryAccessRule)

매개 변수

rule
RegistryAccessRule

제거할 RegistryAccessRule입니다.

예외

rule이(가) null인 경우

예제

다음 코드 예제에서는 메서드가 RemoveAccessRuleSpecific 정확히 일치하는 경우에만 규칙을 제거한다는 것을 보여 줍니다.

이 예제에서는 서로 다른 권한을 허용하는 두 가지 규칙을 만듭니다. 규칙에는 호환되는 상속 및 전파 플래그가 있으므로 두 번째 규칙이 추가되면 첫 번째 규칙과 병합됩니다. 이 예제에서는 메서드를 RemoveAccessRuleSpecific 호출하여 첫 번째 규칙을 지정하지만 규칙이 병합되기 때문에 일치하는 규칙이 없습니다. 그런 다음, 메서드를 RemoveAccessRule 호출하여 병합된 규칙에서 두 번째 규칙을 제거하고 마지막으로 메서드를 RemoveAccessRuleSpecific 호출하여 첫 번째 규칙을 제거합니다.

참고

이 예제에서는 보안 개체를 개체에 RegistryKey 연결하지 않습니다. RegistryKey.GetAccessControl 메서드 및 메서드를 RegistryKey.SetAccessControl 참조하세요.


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

public class Example
{
    public static void Main()
    {
        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 rule1 = new RegistryAccessRule(user, 
            RegistryRights.ReadKey | RegistryRights.WriteKey
                | RegistryRights.Delete, 
            InheritanceFlags.ContainerInherit, 
            PropagationFlags.None, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule1);

        // Add a rule that allows the current user the right
        // right to take ownership of a key, using the same 
        // inheritance and propagation flags. This rule 
        // merges with the first rule.
        RegistryAccessRule rule2 = new RegistryAccessRule(user, 
            RegistryRights.ChangePermissions, 
            InheritanceFlags.ContainerInherit,
            PropagationFlags.None, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule2);

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

        // Attempt to use RemoveRuleSpecific to remove the
        // first rule. The removal fails, because the rule
        // in the RegistrySecurity object has been altered.
        mSec.RemoveAccessRuleSpecific(rule1);

        // Show that the rule was not removed.
        ShowSecurity(mSec);

        // Use the RemoveAccessRule method to remove rule2,
        // and then use RemoveAccessRuleSpecific to remove
        // rule1.
        mSec.RemoveAccessRule(rule2);
        mSec.RemoveAccessRuleSpecific(rule1);

        // Show that the rules have been removed.
        ShowSecurity(mSec);
    }

    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, ChangePermissions
 Inheritance: ContainerInherit
 Propagation: None
   Inherited? False


Current access rules:

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


Current access rules:

*/
Option Explicit
Imports System.Security.AccessControl
Imports System.Security.Principal
Imports System.Security
Imports Microsoft.Win32

Public Class Example

    Public Shared Sub Main()

        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 rule1 As New RegistryAccessRule(user, _
            RegistryRights.ReadKey Or RegistryRights.WriteKey _
                Or RegistryRights.Delete, _
            InheritanceFlags.ContainerInherit, _
            PropagationFlags.None, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule1)

        ' Add a rule that allows the current user the right
        ' right to take ownership of a key, using the same 
        ' inheritance and propagation flags. This rule 
        ' merges with the first rule.
        Dim rule2 As New RegistryAccessRule(user, _
            RegistryRights.ChangePermissions, _
            InheritanceFlags.ContainerInherit, _
            PropagationFlags.None, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule2)

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

        ' Attempt to use RemoveRuleSpecific to remove the
        ' first rule. The removal fails, because the rule
        ' in the RegistrySecurity object has been altered.
        mSec.RemoveAccessRuleSpecific(rule1)

        ' Show that the rule was not removed.
        ShowSecurity(mSec)

        ' Use the RemoveAccessRule method to remove rule2,
        ' and then use RemoveAccessRuleSpecific to remove
        ' rule1.
        mSec.RemoveAccessRule(rule2)
        mSec.RemoveAccessRuleSpecific(rule1)

        ' Show that the rules have been removed.
        ShowSecurity(mSec)

    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, ChangePermissions
' Inheritance: ContainerInherit
' Propagation: None
'   Inherited? False
'
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: SetValue, CreateSubKey, Delete, ReadKey, ChangePermissions
' Inheritance: ContainerInherit
' Propagation: None
'   Inherited? False
'
'
'Current access rules:
'

설명

규칙은 플래그를 포함한 모든 세부 정보에서 정확히 일치하는 rule 경우에만 제거됩니다. 동일한 사용자와 AccessControlType 다른 규칙은 영향을 받지 않습니다.

중요

규칙은 하나 이상의 기본 ACE(액세스 제어 항목)를 나타내며, 이러한 항목은 사용자의 액세스 보안 규칙을 수정할 때 필요에 따라 분할되거나 결합됩니다. 따라서 규칙이 추가될 때 가진 특정 양식에 더 이상 존재하지 않을 수 있으며, 이 경우 메서드가 RemoveAccessRuleSpecific 제거할 수 없습니다.

적용 대상