Aracılığıyla paylaş


RegistrySecurity.RemoveAccessRule(RegistryAccessRule) Yöntem

Tanım

Belirtilen erişim kuralıyla aynı kullanıcıya ve AccessControlType (izin ver veya reddet) ve uyumlu devralma ve yayma bayraklarına sahip bir erişim denetimi kuralı arar; böyle bir kural bulunursa, belirtilen erişim kuralında yer alan haklar bu kuraldan kaldırılır.

public:
 bool RemoveAccessRule(System::Security::AccessControl::RegistryAccessRule ^ rule);
public bool RemoveAccessRule (System.Security.AccessControl.RegistryAccessRule rule);
override this.RemoveAccessRule : System.Security.AccessControl.RegistryAccessRule -> bool
Public Function RemoveAccessRule (rule As RegistryAccessRule) As Boolean

Parametreler

rule
RegistryAccessRule

RegistryAccessRule Kullanıcı ve AccessControlType aranacak öğesini belirten ve bulunan eşleşen bir kuralın uyumlu olması gereken devralma ve yayma bayrakları kümesi. Bulunursa uyumlu kuraldan kaldırılacak hakları belirtir.

Döndürülenler

true uyumlu bir kural bulunursa; aksi takdirde false.

Özel durumlar

rule, null değeridir.

Örnekler

Aşağıdaki kod örneği, yönteminin RemoveAccessRule uyumlu bir kuraldan hakları nasıl kaldırıyor ve yöntemin hakları uyumlu kurallarla nasıl birleştirip birleştiremeyi AddAccessRule gösterir.

Örnek bir RegistrySecurity nesnesi oluşturur ve geçerli kullanıcı RegistryRights.ReadKey haklarına izin veren bir kural ekler. Örnek daha sonra ilk kuralla aynı devralma ve yayma haklarıyla kullanıcıya RegistryRights.SetValueveren bir kural oluşturur ve bu yeni kuralı nesneden RegistrySecurity kaldırmak için yöntemini kullanırRemoveAccessRule. SetValue , öğesinin ReadKeybir parçası olduğundan uyumlu kuraldan kaldırılır. nesnesindeki RegistrySecurity kurallar görüntülenir ve öğesinin kalan bileşenlerini ReadKeygösterir.

Örnek kod daha sonra sağını RemoveAccessRule nesnedeki SetValue kuralla RegistrySecurity birleştirmek için yöntemini çağırır.

Not

Bu örnek, güvenlik nesnesini bir RegistryKey nesneye eklemez. Bu bölümdeki ikinci örnekte bir güvenlik nesnesi ekleniyor ve içindeki RegistryKey.GetAccessControlRegistryKey.SetAccessControlörnekler de ekleniyor.


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 ReadKey
        // rights. ReadKey is a combination of four other 
        // rights. The rule is inherited by all 
        // contained subkeys.
        RegistryAccessRule rule = new RegistryAccessRule(user, 
            RegistryRights.ReadKey, 
            InheritanceFlags.ContainerInherit, 
            PropagationFlags.None, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        // Create a rule that allows the current user only the 
        // right to query the key/value pairs of a key, using  
        // the same inheritance and propagation flags as the
        // first rule. QueryValues is a constituent of 
        // ReadKey, so when this rule is removed, using the 
        // RemoveAccessRule method, ReadKey is broken into
        // its constituent parts.
        rule = new RegistryAccessRule(user, 
            RegistryRights.QueryValues, 
            InheritanceFlags.ContainerInherit, 
            PropagationFlags.None, 
            AccessControlType.Allow);
        mSec.RemoveAccessRule(rule);

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

        // Add the second rule back. It merges with the 
        // existing rule, so that the rule is now displayed
        // as ReadKey.
        mSec.AddAccessRule(rule);

        // Display the rules in the security object.
        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: EnumerateSubKeys, Notify, ReadPermissions
 Inheritance: ContainerInherit
 Propagation: None
   Inherited? False


Current access rules:

        User: TestDomain\TestUser
        Type: Allow
      Rights: ReadKey
 Inheritance: ContainerInherit
 Propagation: None
   Inherited? False
 */
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 ReadKey
        ' rights. ReadKey is a combination of four other 
        ' rights. The rule is inherited by all 
        ' contained subkeys.
        Dim rule As New RegistryAccessRule(user, _
            RegistryRights.ReadKey, _
            InheritanceFlags.ContainerInherit, _
            PropagationFlags.None, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Create a rule that allows the current user only the 
        ' right to query the key/value pairs of a key, using  
        ' the same inheritance and propagation flags as the
        ' first rule. QueryValues is a constituent of 
        ' ReadKey, so when this rule is removed, using the 
        ' RemoveAccessRule method, ReadKey is broken into
        ' its constituent parts.
        rule = New RegistryAccessRule(user, _
            RegistryRights.QueryValues, _
            InheritanceFlags.ContainerInherit, _
            PropagationFlags.None, _
            AccessControlType.Allow)
        mSec.RemoveAccessRule(rule)

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

        ' Add the second rule back. It merges with the 
        ' existing rule, so that the rule is now displayed
        ' as ReadKey.
        mSec.AddAccessRule(rule)

        ' Display the rules in the security object.
        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: EnumerateSubKeys, Notify, ReadPermissions
' Inheritance: ContainerInherit
' Propagation: None
'   Inherited? False
'
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: ReadKey
' Inheritance: ContainerInherit
' Propagation: None
'   Inherited? False
'

Açıklamalar

Geçerli RegistrySecurity , aynı kullanıcıya ve ile aynı AccessControlType değere rulesahip bir kural için arandı. Böyle bir kural bulunmazsa hiçbir eylem yapılmaz ve yöntemi döndürür false. Eşleşen kurallar bulunursa, devralma ve uyumluluk bayrakları içinde rulebelirtilen bayraklarla uyumlu olup olmadığını denetler. Uyumlu bir kural bulunmazsa hiçbir eylem yapılmaz ve yöntemi döndürür false. Uyumlu bayraklara sahip bir kural bulunursa, içinde rule belirtilen haklar uyumlu kuraldan kaldırılır ve yöntemi döndürür true. Uyumlu kuralda bulunmayan hakları belirtirse rule , bu haklarla ilgili hiçbir işlem yapılmaz. Tüm haklar uyumlu kuraldan kaldırılırsa, kuralın tamamı geçerli RegistrySecurity nesneden kaldırılır.

Şunlara uygulanır