语言

RegistryAccessRule 构造函数

定义

初始化 RegistryAccessRule 类的新实例。

重载

名称 说明
RegistryAccessRule(IdentityReference, RegistryRights, AccessControlType)

初始化类的新实例 RegistryAccessRule ,指定规则适用的用户或组、访问权限以及是否允许或拒绝指定的访问权限。

RegistryAccessRule(String, RegistryRights, AccessControlType)

初始化类的新实例 RegistryAccessRule ,指定规则应用于的用户或组的名称、访问权限以及是否允许或拒绝指定的访问权限。

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

初始化类的新实例 RegistryAccessRule ,指定规则适用的用户或组、访问权限、继承标志、传播标志以及是否允许或拒绝指定的访问权限。

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

初始化类的新实例 RegistryAccessRule ,指定规则应用于的用户或组的名称、访问权限、继承标志、传播标志,以及是否允许或拒绝指定的访问权限。

RegistryAccessRule(IdentityReference, RegistryRights, AccessControlType)

Source:
RegistrySecurity.cs

初始化类的新实例 RegistryAccessRule ,指定规则适用的用户或组、访问权限以及是否允许或拒绝指定的访问权限。

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)

参数

identity
IdentityReference

规则适用的用户或组。 必须是类型 SecurityIdentifier 或类型,例如 NTAccount 可以转换为类型 SecurityIdentifier。

registryRights
RegistryRights

指示允许或拒绝权限的值的 RegistryRights 按位组合。

type
AccessControlType

指示 AccessControlType 是允许还是拒绝权限的值之一。

例外

registryRights 指定无效值。

-或-

type 指定无效值。

identity 是 null。

-或-

eventRights 为零。

identity既不是类型SecurityIdentifier,也不是可以转换为类型NTAccount的类型SecurityIdentifier。

注解

此构造函数指定默认传播和继承。 也就是说, InheritanceFlags.None 也是 PropagationFlags.None。

适用于

RegistryAccessRule(String, RegistryRights, AccessControlType)

Source:
RegistrySecurity.cs

初始化类的新实例 RegistryAccessRule ,指定规则应用于的用户或组的名称、访问权限以及是否允许或拒绝指定的访问权限。

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)

参数

identity
String

规则适用的用户或组的名称。

registryRights
RegistryRights

指示允许或拒绝权限的值的 RegistryRights 按位组合。

type
AccessControlType

指示 AccessControlType 是允许还是拒绝权限的值之一。

例外

registryRights 指定无效值。

-或-

type 指定无效值。

registryRights 为零。

identity 是 null。

-或-

identity 是长度为零的字符串。

-或-

identity 长度超过 512 个字符。

示例

下面的代码示例创建注册表访问规则并将其添加到对象 RegistrySecurity ,其中显示了允许和拒绝权限的规则如何保持独立,同时合并相同类型的兼容规则。

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

注解

此构造函数指定默认传播和继承。 也就是说, InheritanceFlags.None 也是 PropagationFlags.None。

此构造函数等效于创建对象NTAccount,方法是传递给identityNTAccount.NTAccount(String)构造函数,并将新创建NTAccount的对象传递给RegistryAccessRule(IdentityReference, RegistryRights, AccessControlType)构造函数。

适用于

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

Source:
RegistrySecurity.cs

初始化类的新实例 RegistryAccessRule ,指定规则适用的用户或组、访问权限、继承标志、传播标志以及是否允许或拒绝指定的访问权限。

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)

参数

identity
IdentityReference

规则适用的用户或组。 必须是类型 SecurityIdentifier 或类型,例如 NTAccount 可以转换为类型 SecurityIdentifier。

registryRights
RegistryRights

指定允许或拒绝权限的值的 RegistryRights 按位组合。

inheritanceFlags
InheritanceFlags

标志的 InheritanceFlags 按位组合,指定如何从其他对象继承访问权限。

propagationFlags
PropagationFlags

标志的 PropagationFlags 按位组合,指定如何将访问权限传播到其他对象。

type
AccessControlType

AccessControlType指定是允许还是拒绝权限的值之一。

例外

registryRights 指定无效值。

-或-

type 指定无效值。

-或-

inheritanceFlags 指定无效值。

-或-

propagationFlags 指定无效值。

identity 是 null。

-或-

registryRights 为零。

identity既不是类型SecurityIdentifier,也不是可以转换为类型的类型NTAccountSecurityIdentifier。

注解

所有注册表项都是容器,因此,对于注册表项有意义的唯一继承标志是 InheritanceFlags.ContainerInherit 标志。 如果未指定此标志,则忽略传播标志,并且仅影响即时键。 如果标志存在,则会传播规则,如下表所示。 该表假定有一个子项 S,子项 CS 和孙子项 GS。 也就是说,孙子子项的路径是 S\CS\GS。

传播标志 S CS GS
None X X X
NoPropagateInherit X X
InheritOnly X X
NoPropagateInherit、InheritOnly X

孙子子项的模式控制孙子项包含的所有子项。

例如,如果 ContainerInherit 为该标志指定 inheritanceFlags 并 InheritOnly 指定 propagationFlags了传播标志,则此规则不适用于即时子项,但应用于其所有直接子项以及它们包含的所有子项。

注释

虽然可以指定标志InheritanceFlags.ObjectInheritinheritanceFlags,但这样做没有意义。 出于访问控制的目的,子项中的名称/值对不是单独的对象。 名称/值对的访问权限由子项的权限控制。 此外,由于所有子项都是容器(即它们可以包含其他子项),因此它们不受标志的影响 ObjectInherit 。 最后,指定 ObjectInherit 标志不需要使规则的维护复杂化,因为它会干扰其他兼容规则的组合。

适用于

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

Source:
RegistrySecurity.cs

初始化类的新实例 RegistryAccessRule ,指定规则应用于的用户或组的名称、访问权限、继承标志、传播标志,以及是否允许或拒绝指定的访问权限。

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)

参数

identity
String

规则适用的用户或组的名称。

registryRights
RegistryRights

指示允许或拒绝权限的值的 RegistryRights 按位组合。

inheritanceFlags
InheritanceFlags

标志的 InheritanceFlags 按位组合,指定如何从其他对象继承访问权限。

propagationFlags
PropagationFlags

标志的 PropagationFlags 按位组合,指定如何将访问权限传播到其他对象。

type
AccessControlType

AccessControlType指定是允许还是拒绝权限的值之一。

例外

registryRights 指定无效值。

-或-

type 指定无效值。

-或-

inheritanceFlags 指定无效值。

-或-

propagationFlags 指定无效值。

eventRights 为零。

identity 是 null。

-或-

identity 是长度为零的字符串。

-或-

identity 长度超过 512 个字符。

示例

下面的代码示例演示了具有继承和传播的访问规则。 该示例创建一个对象,然后创建并添加两个 RegistrySecurity 具有 ContainerInherit 标志的规则。 第一个规则没有传播标志,而第二个规则具有 NoPropagateInherit 和 InheritOnly。

程序在对象中 RegistrySecurity 显示规则,然后使用 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

注解

所有注册表项都是容器,因此,对于注册表项有意义的唯一继承标志是 InheritanceFlags.ContainerInherit 标志。 如果未指定此标志,则忽略传播标志,并且仅影响即时键。 如果标志存在,则会传播规则,如下表所示。 该表假定有一个子项 S,子项 CS 和孙子项 GS。 也就是说,孙子子项的路径是 S\CS\GS。

传播标志 S CS GS
None X X X
NoPropagateInherit X X
InheritOnly X X
NoPropagateInherit、InheritOnly X

孙子子项的模式控制孙子项包含的所有子项。

例如,如果 ContainerInherit 为该标志指定 inheritanceFlags 并 InheritOnly 指定 propagationFlags了传播标志,则此规则不适用于即时子项,但应用于其所有直接子项以及它们包含的所有子项。

注释

虽然可以指定标志InheritanceFlags.ObjectInheritinheritanceFlags,但这样做没有意义。 出于访问控制的目的,子项中的名称/值对不是单独的对象。 名称/值对的访问权限由子项的权限控制。 此外,由于所有子项都是容器(即它们可以包含其他子项),因此它们不受标志的影响 ObjectInherit 。 最后,指定 ObjectInherit 标志不需要使规则的维护复杂化,因为它会干扰其他兼容规则的组合。

此构造函数等效于创建对象NTAccount,方法是传递给identityNTAccount.NTAccount(String)构造函数,并将新创建NTAccount的对象传递给RegistryAccessRule(IdentityReference, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType)构造函数。

适用于