RegistryAccessRuleとは? わかりやすく解説

RegistryAccessRule クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

ユーザーまたはグループ許可されアクセス権セットまたは拒否されアクセス権セット表します。このクラス継承できません。

名前空間: System.Security.AccessControl
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public NotInheritable Class
 RegistryAccessRule
    Inherits AccessRule
Dim instance As RegistryAccessRule
public sealed class RegistryAccessRule : AccessRule
public ref class RegistryAccessRule sealed
 : public AccessRule
public final class RegistryAccessRule extends
 AccessRule
public final class RegistryAccessRule extends
 AccessRule
解説解説

RegistryAccessRule クラスは、レジストリ キーに関する Windowsアクセス制御セキュリティ管理するために .NET Framework提供されるクラスセット含まれています。これらのクラス概要、および基になる Windowsアクセス制御構造との関係については、RegistrySecurity のトピック参照してください

メモメモ

Windowsアクセス制御セキュリティは、レジストリ キーだけに適用できますキー格納されている個別キー/値ペア適用することはできません。

レジストリ キーに現在適用されている規則リスト取得するには、RegistryKey.GetAccessControl メソッド使用して RegistrySecurity オブジェクト取得し、その GetAccessRules メソッド使用して RegistryAccessRule オブジェクトコレクション取得します

RegistryAccessRule オブジェクトは、基になる随意アクセス制御リスト (DACL: Discretionary Access Control List) のアクセス制御エントリと一対一には対応していません。レジストリ キーに関するすべてのアクセス規則セット取得する場合、このセットには、すべてのアクセス制御エントリを表すために現在必要な最低限の数の規則だけが含まれます。

RegistryAccessRule オブジェクト使用してユーザーまたはグループ許可するアクセス権または拒否するアクセス権指定しますRegistryAccessRule オブジェクトは、許可されアクセス権または拒否されアクセス権どちらか一方表します両方を表すことはありません。

レジストリ キー規則適用するには、RegistryKey.GetAccessControl メソッド使用して RegistrySecurity オブジェクト取得します規則追加するメソッド使用して RegistrySecurity オブジェクト変更し、RegistryKey.SetAccessControl メソッド使用してセキュリティ オブジェクト再度割り当てます

RegistryAccessRule オブジェクト変更不可です。レジストリ キーセキュリティは、RegistrySecurity クラスメソッド使用して規則追加または削除することにより変更します。この操作によって、基になるアクセス制御エントリが変更されます。

使用例使用例

継承反映を行うアクセス規則コード例次に示します。この例では、RegistrySecurity オブジェクト作成し、ContainerInherit フラグを持つ 2 つ規則作成して追加します最初規則には、反映フラグがありません。2 番目の規則には、NoPropagateInherit と InheritOnly が存在します

このプログラムでは、RegistrySecurity オブジェクト内の規則表示し、このオブジェクト使用してサブキーを作成します。さらに、子サブキーと孫サブキーを作成し、各サブキーのセキュリティ表示します最後にテスト キー削除します

Option Explicit
Imports System
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
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
 */
継承階層継承階層
System.Object
   System.Security.AccessControl.AuthorizationRule
     System.Security.AccessControl.AccessRule
      System.Security.AccessControl.RegistryAccessRule
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RegistryAccessRule メンバ
System.Security.AccessControl 名前空間

RegistryAccessRule コンストラクタ (String, RegistryRights, AccessControlType)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

規則適用するユーザーまたはグループの名前、アクセス権、および指定したアクセス権許可するかどうか指定して、RegistryAccessRule クラス新しインスタンス初期化します。

名前空間: System.Security.AccessControl
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    identity As String, _
    registryRights As RegistryRights, _
    type As AccessControlType _
)
Dim identity As String
Dim registryRights As RegistryRights
Dim type As AccessControlType

Dim instance As New RegistryAccessRule(identity,
 registryRights, type)
public RegistryAccessRule (
    string identity,
    RegistryRights registryRights,
    AccessControlType type
)
public:
RegistryAccessRule (
    String^ identity, 
    RegistryRights registryRights, 
    AccessControlType type
)
public RegistryAccessRule (
    String identity, 
    RegistryRights registryRights, 
    AccessControlType type
)
public function RegistryAccessRule (
    identity : String, 
    registryRights : RegistryRights, 
    type : AccessControlType
)

パラメータ

identity

規則適用対象となるユーザー名またはグループ名。

registryRights

許可されアクセス権または拒否されアクセス権を表す RegistryRights 値のビットごとの組み合わせ

type

アクセス権許可されているかどうかを表す AccessControlType 値の 1 つ

例外例外
例外種類条件

ArgumentOutOfRangeException

registryRights無効な値が指定されています。

または

type無効な値が指定されています。

ArgumentNullException

registryRights が 0 です。

ArgumentException

identitynull 参照 (Visual Basic では Nothing) です。

または

identity は、長さ 0 の文字列です。

または

identity512 文字超えてます。

解説解説

このコンストラクタは、既定反映継承指定します。つまり、InheritanceFlags.None と PropagationFlags.None です。

このコンストラクタは、identity を System.Security.Principal.NTAccount(String) コンストラクタ渡し新しく作成した NTAccount オブジェクトを RegistryAccessRule(IdentityReference,RegistryRights,AccessControlType) コンストラクタ渡してNTAccount オブジェクト作成するのと同じ働きをします。

使用例使用例

レジストリ アクセス規則作成し、RegistrySecurity オブジェクト追加するコード例次に示しますまた、アクセス権許可する規則拒否する規則別々に保存され、同じ種類互換性がある規則マージされることも示します

Imports System
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
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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RegistryAccessRule クラス
RegistryAccessRule メンバ
System.Security.AccessControl 名前空間

RegistryAccessRule コンストラクタ (String, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

規則適用するユーザーまたはグループの名前、アクセス権継承フラグ反映フラグ、および指定したアクセス権許可するかどうか指定して、RegistryAccessRule クラス新しインスタンス初期化します。

名前空間: System.Security.AccessControl
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    identity As String, _
    registryRights As RegistryRights, _
    inheritanceFlags As InheritanceFlags, _
    propagationFlags As PropagationFlags, _
    type As AccessControlType _
)
Dim identity As String
Dim registryRights As RegistryRights
Dim inheritanceFlags As InheritanceFlags
Dim propagationFlags As PropagationFlags
Dim type As AccessControlType

Dim instance As New RegistryAccessRule(identity,
 registryRights, inheritanceFlags, propagationFlags, type)
public RegistryAccessRule (
    string identity,
    RegistryRights registryRights,
    InheritanceFlags inheritanceFlags,
    PropagationFlags propagationFlags,
    AccessControlType type
)
public:
RegistryAccessRule (
    String^ identity, 
    RegistryRights registryRights, 
    InheritanceFlags inheritanceFlags, 
    PropagationFlags propagationFlags, 
    AccessControlType type
)
public RegistryAccessRule (
    String identity, 
    RegistryRights registryRights, 
    InheritanceFlags inheritanceFlags, 
    PropagationFlags propagationFlags, 
    AccessControlType type
)
public function RegistryAccessRule (
    identity : String, 
    registryRights : RegistryRights, 
    inheritanceFlags : InheritanceFlags, 
    propagationFlags : PropagationFlags, 
    type : AccessControlType
)

パラメータ

identity

規則適用対象となるユーザー名またはグループ名。

registryRights

許可されアクセス権または拒否されアクセス権を表す RegistryRights 値のビットごとの組み合わせ

inheritanceFlags

他のオブジェクトからアクセス権継承する方法指定する InheritanceFlags フラグビットごとの組み合わせ

propagationFlags

他のオブジェクトアクセス権反映させる方法指定する PropagationFlags フラグビットごとの組み合わせ

type

アクセス権許可されているかどうか指定する AccessControlType 値の 1 つ

例外例外
例外種類条件

ArgumentOutOfRangeException

registryRights無効な値が指定されています。

または

type無効な値が指定されています。

または

inheritanceFlags無効な値が指定されています。

または

propagationFlags無効な値が指定されています。

ArgumentNullException

eventRights が 0 です。

ArgumentException

identitynull 参照 (Visual Basic では Nothing) です。

または

identity は、長さ 0 の文字列です。

または

identity512 文字超えてます。

解説解説

すべてのレジストリ キーコンテナなので、レジストリ キーに対して有効な継承フラグは、InheritanceFlags.ContainerInherit フラグだけです。このフラグ指定しないと、反映フラグ無視され直接キーだけが影響受けます。このフラグ存在する場合次の表に示すように、規則反映されます。この表では、サブキー S が存在し、このサブキー S に子サブキー CS と孫サブキー GS含まれていることを前提にしています。そのため、孫サブキーへのパスは、S\CS\GSなります

反映フラグ

S

CS

GS

None

X

X

X

NoPropagateInherit

X

X

 

InheritOnly

 

X

X

NoPropagateInherit, InheritOnly

 

X

 

孫サブキーのパターンは、孫サブキーによって格納されるすべてのサブキーに適用されます。

たとえば、inheritanceFlags に対して ContainerInherit フラグ指定しpropagationFlags に対して InheritOnly 反映フラグ指定すると、この規則は、直接のサブキーには適用されず、そのすべての直接の子サブキーとそれらの子サブキーに格納されるすべてのサブキーに適用されます。

メモメモ

inheritanceFlags に InheritanceFlags.ObjectInherit フラグ指定することもできますが、意味がありません。アクセス制御という目的上、サブキー内の名前と値のペア別個のオブジェクトはなっていません。名前と値のペア対すアクセス権は、サブキーの権限によって制御されます。さらに、すべてのサブキーがコンテナであり、他のサブキーを含めることができるため、ObjectInherit フラグ影響を受けません。また、ObjectInherit フラグ指定すると、互換性がある規則干渉するため、規則管理必要以上に困難になります

このコンストラクタは、identity を System.Security.Principal.NTAccount(String) コンストラクタ渡し新しく作成した NTAccount オブジェクトを RegistryAccessRule(IdentityReference,RegistryRights,InheritanceFlags,PropagationFlags,AccessControlType) コンストラクタ渡してNTAccount オブジェクト作成するのと同じ働きをします。

使用例使用例

継承反映を行うアクセス規則コード例次に示します。この例では、RegistrySecurity オブジェクト作成しContainerInherit フラグを持つ 2 つ規則作成して追加します最初規則には、反映フラグがありません。2 番目の規則には、NoPropagateInheritInheritOnly存在します

このプログラムでは、RegistrySecurity オブジェクト内の規則表示しRegistrySecurity オブジェクト使用してサブキーを作成します。さらに、子サブキーと孫サブキーを作成し、各サブキーの規則表示します最後にテスト キー削除します

Option Explicit
Imports System
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
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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RegistryAccessRule クラス
RegistryAccessRule メンバ
System.Security.AccessControl 名前空間

RegistryAccessRule コンストラクタ (IdentityReference, RegistryRights, AccessControlType)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

規則適用するユーザーまたはグループアクセス権、および指定したアクセス権許可するかどうか指定して、RegistryAccessRule クラス新しインスタンス初期化します。

名前空間: System.Security.AccessControl
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    identity As IdentityReference, _
    registryRights As RegistryRights, _
    type As AccessControlType _
)
Dim identity As IdentityReference
Dim registryRights As RegistryRights
Dim type As AccessControlType

Dim instance As New RegistryAccessRule(identity,
 registryRights, type)
public RegistryAccessRule (
    IdentityReference identity,
    RegistryRights registryRights,
    AccessControlType type
)
public:
RegistryAccessRule (
    IdentityReference^ identity, 
    RegistryRights registryRights, 
    AccessControlType type
)
public RegistryAccessRule (
    IdentityReference identity, 
    RegistryRights registryRights, 
    AccessControlType type
)
public function RegistryAccessRule (
    identity : IdentityReference, 
    registryRights : RegistryRights, 
    type : AccessControlType
)

パラメータ

identity

規則適用対象となるユーザーまたはグループSecurityIdentifier 型にするか、または SecurityIdentifier 型に変換できる NTAccount などの型にする必要があります

registryRights

許可されアクセス権または拒否されアクセス権を表す RegistryRights 値のビットごとの組み合わせ

type

アクセス権許可されているかどうかを表す AccessControlType 値の 1 つ

例外例外
例外種類条件

ArgumentOutOfRangeException

registryRights無効な値が指定されています。

または

type無効な値が指定されています。

ArgumentNullException

identitynull 参照 (Visual Basic では Nothing) です。

または

eventRights が 0 です。

ArgumentException

identitySecurityIdentifierではなくSecurityIdentifier 型に変換できる NTAccount などの型でもありません。

解説解説

このコンストラクタは、既定反映継承指定します。つまり、InheritanceFlags.None と PropagationFlags.None です。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RegistryAccessRule クラス
RegistryAccessRule メンバ
System.Security.AccessControl 名前空間

RegistryAccessRule コンストラクタ (IdentityReference, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

規則適用するユーザーまたはグループアクセス権継承フラグ反映フラグ、および指定したアクセス権許可するかどうか指定して、RegistryAccessRule クラス新しインスタンス初期化します。

名前空間: System.Security.AccessControl
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    identity As IdentityReference, _
    registryRights As RegistryRights, _
    inheritanceFlags As InheritanceFlags, _
    propagationFlags As PropagationFlags, _
    type As AccessControlType _
)
Dim identity As IdentityReference
Dim registryRights As RegistryRights
Dim inheritanceFlags As InheritanceFlags
Dim propagationFlags As PropagationFlags
Dim type As AccessControlType

Dim instance As New RegistryAccessRule(identity,
 registryRights, inheritanceFlags, propagationFlags, type)
public RegistryAccessRule (
    IdentityReference identity,
    RegistryRights registryRights,
    InheritanceFlags inheritanceFlags,
    PropagationFlags propagationFlags,
    AccessControlType type
)
public:
RegistryAccessRule (
    IdentityReference^ identity, 
    RegistryRights registryRights, 
    InheritanceFlags inheritanceFlags, 
    PropagationFlags propagationFlags, 
    AccessControlType type
)
public RegistryAccessRule (
    IdentityReference identity, 
    RegistryRights registryRights, 
    InheritanceFlags inheritanceFlags, 
    PropagationFlags propagationFlags, 
    AccessControlType type
)
public function RegistryAccessRule (
    identity : IdentityReference, 
    registryRights : RegistryRights, 
    inheritanceFlags : InheritanceFlags, 
    propagationFlags : PropagationFlags, 
    type : AccessControlType
)

パラメータ

identity

規則適用対象となるユーザーまたはグループSecurityIdentifier 型にするか、または SecurityIdentifier 型に変換できる NTAccount などの型にする必要があります

registryRights

許可されアクセス権または拒否されアクセス権指定する RegistryRights 値のビットごとの組み合わせ

inheritanceFlags

他のオブジェクトからアクセス権継承する方法指定する InheritanceFlags フラグビットごとの組み合わせ

propagationFlags

他のオブジェクトアクセス権反映させる方法指定する PropagationFlags フラグビットごとの組み合わせ

type

アクセス権許可されているかどうか指定する AccessControlType 値の 1 つ

例外例外
例外種類条件

ArgumentOutOfRangeException

registryRights無効な値が指定されています。

または

type無効な値が指定されています。

または

inheritanceFlags無効な値が指定されています。

または

propagationFlags無効な値が指定されています。

ArgumentNullException

identitynull 参照 (Visual Basic では Nothing) です。

または

registryRights が 0 です。

ArgumentException

identitySecurityIdentifierではなくSecurityIdentifier 型に変換できる NTAccount などの型でもありません。

解説解説

すべてのレジストリ キーコンテナなので、レジストリ キーに対して有効な継承フラグは、InheritanceFlags.ContainerInherit フラグだけです。このフラグ指定しないと、反映フラグ無視され直接キーだけが影響受けます。このフラグ存在する場合次の表に示すように、規則反映されます。この表では、サブキー S が存在し、このサブキー S に子サブキー CS と孫サブキー GS含まれていることを前提にしています。そのため、孫サブキーへのパスは、S\CS\GSなります

反映フラグ

S

CS

GS

None

X

X

X

NoPropagateInherit

X

X

 

InheritOnly

 

X

X

NoPropagateInherit, InheritOnly

 

X

 

孫サブキーのパターンは、孫サブキーによって格納されるすべてのサブキーに適用されます。

たとえば、inheritanceFlags に対して ContainerInherit フラグ指定しpropagationFlags に対して InheritOnly 反映フラグ指定すると、この規則は、直接のサブキーには適用されず、そのすべての直接の子サブキーとそれらの子サブキーに格納されるすべてのサブキーに適用されます。

メモメモ

inheritanceFlags に InheritanceFlags.ObjectInherit フラグ指定することもできますが、意味がありません。アクセス制御という目的上、サブキー内の名前と値のペア別個のオブジェクトはなっていません。名前と値のペア対すアクセス権は、サブキーの権限によって制御されます。さらに、すべてのサブキーがコンテナであり、他のサブキーを含めることができるため、ObjectInherit フラグ影響を受けません。また、ObjectInherit フラグ指定すると、互換性がある規則干渉するため、規則管理必要以上に困難になります

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RegistryAccessRule クラス
RegistryAccessRule メンバ
System.Security.AccessControl 名前空間

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 クラス
RegistryAccessRule メンバ
System.Security.AccessControl 名前空間

RegistryAccessRule プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ AccessControlType  この AccessRule オブジェクト関連付けられている AccessControlType 値を取得します。 ( AccessRule から継承されます。)
パブリック プロパティ IdentityReference  この規則適用する IdentityReference を取得します。 ( AuthorizationRule から継承されます。)
パブリック プロパティ InheritanceFlags  この規則を子オブジェクト継承する方法決定するフラグの値を取得します。 ( AuthorizationRule から継承されます。)
パブリック プロパティ IsInherited  この規則明示的に設定するか、または親コンテナ オブジェクトから継承するかを指定する値を取得します。 ( AuthorizationRule から継承されます。)
パブリック プロパティ PropagationFlags  反映フラグの値を取得します。このフラグから、この規則を子オブジェクト反映させる方法判断します。このプロパティ重要なのは、InheritanceFlags 列挙体の値が None でない場合だけです。 ( AuthorizationRule から継承されます。)
パブリック プロパティ RegistryRights アクセス規則許可されアクセス権または拒否されアクセス権取得します
参照参照

関連項目

RegistryAccessRule クラス
System.Security.AccessControl 名前空間

RegistryAccessRule メソッド


RegistryAccessRule メンバ

ユーザーまたはグループ許可されアクセス権セットまたは拒否されアクセス権セット表します。このクラス継承できません。

RegistryAccessRule データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド RegistryAccessRule オーバーロードされます。 RegistryAccessRule クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ AccessControlType  この AccessRule オブジェクト関連付けられている AccessControlType 値を取得します。(AccessRule から継承されます。)
パブリック プロパティ IdentityReference  この規則適用する IdentityReference を取得します。(AuthorizationRule から継承されます。)
パブリック プロパティ InheritanceFlags  この規則を子オブジェクト継承する方法決定するフラグの値を取得します。(AuthorizationRule から継承されます。)
パブリック プロパティ IsInherited  この規則明示的に設定するか、または親コンテナ オブジェクトから継承するかを指定する値を取得します。(AuthorizationRule から継承されます。)
パブリック プロパティ PropagationFlags  反映フラグの値を取得します。このフラグから、この規則を子オブジェクト反映させる方法判断します。このプロパティ重要なのは、InheritanceFlags 列挙体の値が None でない場合だけです。(AuthorizationRule から継承されます。)
パブリック プロパティ RegistryRights アクセス規則許可されアクセス権または拒否されアクセス権取得します
パブリック メソッドパブリック メソッド
参照参照

関連項目

RegistryAccessRule クラス
System.Security.AccessControl 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「RegistryAccessRule」の関連用語

RegistryAccessRuleのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



RegistryAccessRuleのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS