RegistryAccessRule Constructors

Definitie

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse.

Overloads

Name Description
RegistryAccessRule(IdentityReference, RegistryRights, AccessControlType)

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse, waarbij u de gebruiker of groep opgeeft waarop de regel van toepassing is, de toegangsrechten en of de opgegeven toegangsrechten zijn toegestaan of geweigerd.

RegistryAccessRule(String, RegistryRights, AccessControlType)

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse, waarbij u de naam van de gebruiker of groep opgeeft waarop de regel van toepassing is, de toegangsrechten en of de opgegeven toegangsrechten zijn toegestaan of geweigerd.

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

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse, waarbij u de gebruiker of groep opgeeft waarop de regel van toepassing is, de toegangsrechten, de overnamevlagmen, de doorgiftevlagmen en of de opgegeven toegangsrechten zijn toegestaan of geweigerd.

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

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse, waarbij u de naam van de gebruiker of groep opgeeft waarop de regel van toepassing is, de toegangsrechten, de overnamevlagmen, de doorgiftevlagmen en of de opgegeven toegangsrechten zijn toegestaan of geweigerd.

RegistryAccessRule(IdentityReference, RegistryRights, AccessControlType)

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse, waarbij u de gebruiker of groep opgeeft waarop de regel van toepassing is, de toegangsrechten en of de opgegeven toegangsrechten zijn toegestaan of geweigerd.

public:
 RegistryAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::RegistryRights registryRights, System::Security::AccessControl::AccessControlType type);
public RegistryAccessRule(System.Security.Principal.IdentityReference identity, System.Security.AccessControl.RegistryRights registryRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.RegistryAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.RegistryRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.RegistryAccessRule
Public Sub New (identity As IdentityReference, registryRights As RegistryRights, type As AccessControlType)

Parameters

identity
IdentityReference

De gebruiker of groep waar de regel op van toepassing is. Moet van het type SecurityIdentifier zijn of een type, zoals NTAccount dat kan worden geconverteerd naar type SecurityIdentifier.

registryRights
RegistryRights

Een bitsgewijze combinatie van RegistryRights waarden die aangeven welke rechten zijn toegestaan of geweigerd.

type
AccessControlType

Een van de AccessControlType waarden die aangeven of de rechten zijn toegestaan of geweigerd.

Uitzonderingen

registryRights geeft een ongeldige waarde op.

– of –

type geeft een ongeldige waarde op.

identity is null.

– of –

eventRights is nul.

identity is geen van het type SecurityIdentifier noch van een type, zoals NTAccount dat kan worden geconverteerd naar type SecurityIdentifier.

Opmerkingen

Deze constructor geeft standaarddoorgifte en overname aan. Dat is, InheritanceFlags.None en PropagationFlags.None.

Van toepassing op

RegistryAccessRule(String, RegistryRights, AccessControlType)

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse, waarbij u de naam van de gebruiker of groep opgeeft waarop de regel van toepassing is, de toegangsrechten en of de opgegeven toegangsrechten zijn toegestaan of geweigerd.

public:
 RegistryAccessRule(System::String ^ identity, System::Security::AccessControl::RegistryRights registryRights, System::Security::AccessControl::AccessControlType type);
public RegistryAccessRule(string identity, System.Security.AccessControl.RegistryRights registryRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.RegistryAccessRule : string * System.Security.AccessControl.RegistryRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.RegistryAccessRule
Public Sub New (identity As String, registryRights As RegistryRights, type As AccessControlType)

Parameters

identity
String

De naam van de gebruiker of groep waar de regel op van toepassing is.

registryRights
RegistryRights

Een bitsgewijze combinatie van RegistryRights waarden die aangeven welke rechten zijn toegestaan of geweigerd.

type
AccessControlType

Een van de AccessControlType waarden die aangeven of de rechten zijn toegestaan of geweigerd.

Uitzonderingen

registryRights geeft een ongeldige waarde op.

– of –

type geeft een ongeldige waarde op.

registryRights is nul.

identity is null.

– of –

identity is een tekenreeks met lengte nul.

– of –

identity is langer dan 512 tekens.

Voorbeelden

In het volgende codevoorbeeld worden registertoegangsregels gemaakt en toegevoegd aan een RegistrySecurity object, waarin wordt getoond hoe regels die rechten toestaan en weigeren gescheiden blijven, terwijl compatibele regels van hetzelfde type worden samengevoegd.

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

public class Example
{
    public static void Main()
    {
        // Create a string representing the current user.
        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 the key.
        RegistryAccessRule rule = new RegistryAccessRule(user, 
            RegistryRights.ReadKey, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        // Add a rule that denies the current user the 
        // right to change permissions on the Registry.
        rule = new RegistryAccessRule(user, 
            RegistryRights.ChangePermissions, 
            AccessControlType.Deny);
        mSec.AddAccessRule(rule);

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

        // Add a rule that allows the current user the 
        // right to read permissions on the Registry. This 
        // rule is merged with the existing Allow rule.
        rule = new RegistryAccessRule(user, 
            RegistryRights.WriteKey, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        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();
        }
    }
}

/* This code example produces output similar to following:

Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: ReadKey


Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: SetValue, CreateSubKey, ReadKey
 */
Imports Microsoft.Win32
Imports System.Security.AccessControl
Imports System.Security.Principal

Public Class Example

    Public Shared Sub Main()

        ' Create a string representing the current user.
        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 the key.
        Dim rule As New RegistryAccessRule(user, _
            RegistryRights.ReadKey, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Add a rule that denies the current user the 
        ' right to change permissions on the Registry.
        rule = New RegistryAccessRule(user, _
            RegistryRights.ChangePermissions, _
            AccessControlType.Deny)
        mSec.AddAccessRule(rule)

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

        ' Add a rule that allows the current user the 
        ' right to read permissions on the Registry. This 
        ' rule is merged with the existing Allow rule.
        rule = New RegistryAccessRule(user, _
            RegistryRights.WriteKey, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        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()
        Next

    End Sub
End Class 

'This code example produces output similar to following:
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: ReadKey
'
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: SetValue, CreateSubKey, ReadKey

Opmerkingen

Deze constructor geeft standaarddoorgifte en overname aan. Dat is, InheritanceFlags.None en PropagationFlags.None.

Deze constructor is gelijk aan het maken van een NTAccount object door te geven identity aan de NTAccount.NTAccount(String) constructor en het zojuist gemaakte NTAccount object door te geven aan de RegistryAccessRule(IdentityReference, RegistryRights, AccessControlType) constructor.

Van toepassing op

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

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse, waarbij u de gebruiker of groep opgeeft waarop de regel van toepassing is, de toegangsrechten, de overnamevlagmen, de doorgiftevlagmen en of de opgegeven toegangsrechten zijn toegestaan of geweigerd.

public:
 RegistryAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::RegistryRights registryRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AccessControlType type);
public RegistryAccessRule(System.Security.Principal.IdentityReference identity, System.Security.AccessControl.RegistryRights registryRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.RegistryAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.RegistryRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.RegistryAccessRule
Public Sub New (identity As IdentityReference, registryRights As RegistryRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, type As AccessControlType)

Parameters

identity
IdentityReference

De gebruiker of groep waar de regel op van toepassing is. Moet van het type SecurityIdentifier zijn of een type, zoals NTAccount dat kan worden geconverteerd naar type SecurityIdentifier.

registryRights
RegistryRights

Een bitsgewijze combinatie van RegistryRights waarden waarmee de rechten worden opgegeven die zijn toegestaan of geweigerd.

inheritanceFlags
InheritanceFlags

Een bitsgewijze combinatie van InheritanceFlags vlaggen die aangeven hoe toegangsrechten worden overgenomen van andere objecten.

propagationFlags
PropagationFlags

Een bitsgewijze combinatie van PropagationFlags vlaggen die aangeven hoe toegangsrechten worden doorgegeven aan andere objecten.

type
AccessControlType

Een van de AccessControlType waarden die aangeven of de rechten zijn toegestaan of geweigerd.

Uitzonderingen

registryRights geeft een ongeldige waarde op.

– of –

type geeft een ongeldige waarde op.

– of –

inheritanceFlags geeft een ongeldige waarde op.

– of –

propagationFlags geeft een ongeldige waarde op.

identity is null.

– of –

registryRights is nul.

identity is geen van het type SecurityIdentifier, noch van een type zoals NTAccount dat kan worden geconverteerd naar type SecurityIdentifier.

Opmerkingen

Alle registersleutels zijn containers, dus de enige overnamevlag die zinvol is voor registersleutels is de InheritanceFlags.ContainerInherit vlag. Als deze vlag niet is opgegeven, worden de doorgiftevlagmen genegeerd en wordt alleen de directe sleutel beïnvloed. Als de vlag aanwezig is, wordt de regel doorgegeven zoals wordt weergegeven in de volgende tabel. In de tabel wordt ervan uitgegaan dat er een subsleutel S met onderliggende subsleutel CS en kleinkind subsleutel GS is. Dat wil gezegd, het pad voor de subsleutel voor kleinkind is S\CS\GS.

Doorgiftevlagmen S CS GS
None X X X
NoPropagateInherit X X
InheritOnly X X
NoPropagateInherit, InheritOnly X

Het patroon voor de subsleutel voor kleinkind bepaalt alle subsleutels die zijn opgenomen in de subsleutel voor kleinkind.

Als de ContainerInherit vlag bijvoorbeeld is opgegeven en de InheritOnly doorgiftevlag is opgegeven inheritanceFlagspropagationFlags, is deze regel niet van toepassing op de onmiddellijke subsleutel, maar geldt dit voor alle onderliggende subsleutels en voor alle subsleutels die ze bevatten.

Note

Hoewel u de InheritanceFlags.ObjectInherit vlag voor inheritanceFlagskunt opgeven, is er geen punt om dit te doen. Voor toegangsbeheer zijn de naam-/waardeparen in een subsleutel geen afzonderlijke objecten. De toegangsrechten voor naam-/waardeparen worden bepaald door de rechten van de subsleutel. Aangezien alle subsleutels containers zijn (dat wil gezegd, ze andere subsleutels kunnen bevatten), worden ze niet beïnvloed door de ObjectInherit vlag. Ten slotte maakt het opgeven van de ObjectInherit vlag onnodig het onderhoud van regels ingewikkeld, omdat deze de combinatie van anders compatibele regels verstoort.

Van toepassing op

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

Initialiseert een nieuw exemplaar van de RegistryAccessRule klasse, waarbij u de naam van de gebruiker of groep opgeeft waarop de regel van toepassing is, de toegangsrechten, de overnamevlagmen, de doorgiftevlagmen en of de opgegeven toegangsrechten zijn toegestaan of geweigerd.

public:
 RegistryAccessRule(System::String ^ identity, System::Security::AccessControl::RegistryRights registryRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AccessControlType type);
public RegistryAccessRule(string identity, System.Security.AccessControl.RegistryRights registryRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.RegistryAccessRule : string * System.Security.AccessControl.RegistryRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.RegistryAccessRule
Public Sub New (identity As String, registryRights As RegistryRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, type As AccessControlType)

Parameters

identity
String

De naam van de gebruiker of groep waar de regel op van toepassing is.

registryRights
RegistryRights

Een bitsgewijze combinatie van RegistryRights waarden die aangeven welke rechten zijn toegestaan of geweigerd.

inheritanceFlags
InheritanceFlags

Een bitsgewijze combinatie van InheritanceFlags vlaggen die aangeven hoe toegangsrechten worden overgenomen van andere objecten.

propagationFlags
PropagationFlags

Een bitsgewijze combinatie van PropagationFlags vlaggen die aangeven hoe toegangsrechten worden doorgegeven aan andere objecten.

type
AccessControlType

Een van de AccessControlType waarden die aangeven of de rechten zijn toegestaan of geweigerd.

Uitzonderingen

registryRights geeft een ongeldige waarde op.

– of –

type geeft een ongeldige waarde op.

– of –

inheritanceFlags geeft een ongeldige waarde op.

– of –

propagationFlags geeft een ongeldige waarde op.

eventRights is nul.

identity is null.

– of –

identity is een tekenreeks met lengte nul.

– of –

identity is langer dan 512 tekens.

Voorbeelden

In het volgende codevoorbeeld ziet u toegangsregels met overname en doorgifte. In het voorbeeld wordt een RegistrySecurity object gemaakt en vervolgens twee regels gemaakt en toegevoegd met de ContainerInherit vlag. De eerste regel heeft geen doorgiftevlagmen, terwijl de tweede en NoPropagateInheritInheritOnly.

Het programma geeft de regels in het RegistrySecurity object weer en gebruikt vervolgens het RegistrySecurity object om een subsleutel te maken. Het programma maakt een onderliggende subsleutel en een subsleutel met kleinkind en geeft vervolgens de regels voor elke subsleutel weer. Ten slotte verwijdert het programma de testsleutels.


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

Opmerkingen

Alle registersleutels zijn containers, dus de enige overnamevlag die zinvol is voor registersleutels is de InheritanceFlags.ContainerInherit vlag. Als deze vlag niet is opgegeven, worden de doorgiftevlagmen genegeerd en wordt alleen de directe sleutel beïnvloed. Als de vlag aanwezig is, wordt de regel doorgegeven zoals wordt weergegeven in de volgende tabel. In de tabel wordt ervan uitgegaan dat er een subsleutel S met onderliggende subsleutel CS en kleinkind subsleutel GS is. Dat wil gezegd, het pad voor de subsleutel voor kleinkind is S\CS\GS.

Doorgiftevlagmen S CS GS
None X X X
NoPropagateInherit X X
InheritOnly X X
NoPropagateInherit, InheritOnly X

Het patroon voor de subsleutel voor kleinkind bepaalt alle subsleutels die zijn opgenomen in de subsleutel voor kleinkind.

Als de ContainerInherit vlag bijvoorbeeld is opgegeven en de InheritOnly doorgiftevlag is opgegeven inheritanceFlagspropagationFlags, is deze regel niet van toepassing op de onmiddellijke subsleutel, maar geldt dit voor alle onderliggende subsleutels en voor alle subsleutels die ze bevatten.

Note

Hoewel u de InheritanceFlags.ObjectInherit vlag voor inheritanceFlagskunt opgeven, is er geen punt om dit te doen. Voor toegangsbeheer zijn de naam-/waardeparen in een subsleutel geen afzonderlijke objecten. De toegangsrechten voor naam-/waardeparen worden bepaald door de rechten van de subsleutel. Aangezien alle subsleutels containers zijn (dat wil gezegd, ze andere subsleutels kunnen bevatten), worden ze niet beïnvloed door de ObjectInherit vlag. Ten slotte maakt het opgeven van de ObjectInherit vlag onnodig het onderhoud van regels ingewikkeld, omdat deze de combinatie van anders compatibele regels verstoort.

Deze constructor is gelijk aan het maken van een NTAccount object door te geven identity aan de NTAccount.NTAccount(String) constructor en het zojuist gemaakte NTAccount object door te geven aan de RegistryAccessRule(IdentityReference, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType) constructor.

Van toepassing op