RegistryAccessRule クラス
アセンブリ: mscorlib (mscorlib.dll 内)


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 メソッドを使用してセキュリティ オブジェクトを再度割り当てます。
![]() |
---|
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.Security.AccessControl.AuthorizationRule
System.Security.AccessControl.AccessRule
System.Security.AccessControl.RegistryAccessRule


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RegistryAccessRule コンストラクタ (String, RegistryRights, AccessControlType)
アセンブリ: 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 )


このコンストラクタは、既定の反映と継承を指定します。つまり、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 */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RegistryAccessRule コンストラクタ (String, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType)
アセンブリ: 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 )


すべてのレジストリ キーはコンテナなので、レジストリ キーに対して有効な継承フラグは、InheritanceFlags.ContainerInherit フラグだけです。このフラグを指定しないと、反映フラグは無視され、直接のキーだけが影響を受けます。このフラグが存在する場合、次の表に示すように、規則が反映されます。この表では、サブキー S が存在し、このサブキー S に子サブキー CS と孫サブキー GS が含まれていることを前提にしています。そのため、孫サブキーへのパスは、S\CS\GS になります。
孫サブキーのパターンは、孫サブキーによって格納されるすべてのサブキーに適用されます。
たとえば、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 番目の規則には、NoPropagateInherit と InheritOnly が存在します。
このプログラムでは、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 */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RegistryAccessRule コンストラクタ (IdentityReference, RegistryRights, AccessControlType)
アセンブリ: 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 などの型にする必要があります。



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RegistryAccessRule コンストラクタ (IdentityReference, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType)
アセンブリ: 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 などの型にする必要があります。

例外の種類 | 条件 |
---|---|
ArgumentOutOfRangeException | registryRights に無効な値が指定されています。 または または inheritanceFlags に無効な値が指定されています。 または |
ArgumentNullException | identity が null 参照 (Visual Basic では Nothing) です。 または registryRights が 0 です。 |
ArgumentException | identity が SecurityIdentifier 型ではなく、SecurityIdentifier 型に変換できる NTAccount などの型でもありません。 |

すべてのレジストリ キーはコンテナなので、レジストリ キーに対して有効な継承フラグは、InheritanceFlags.ContainerInherit フラグだけです。このフラグを指定しないと、反映フラグは無視され、直接のキーだけが影響を受けます。このフラグが存在する場合、次の表に示すように、規則が反映されます。この表では、サブキー S が存在し、このサブキー S に子サブキー CS と孫サブキー GS が含まれていることを前提にしています。そのため、孫サブキーへのパスは、S\CS\GS になります。
孫サブキーのパターンは、孫サブキーによって格納されるすべてのサブキーに適用されます。
たとえば、inheritanceFlags に対して ContainerInherit フラグを指定し、propagationFlags に対して InheritOnly 反映フラグを指定すると、この規則は、直接のサブキーには適用されず、そのすべての直接の子サブキーとそれらの子サブキーに格納されるすべてのサブキーに適用されます。
![]() |
---|
inheritanceFlags に InheritanceFlags.ObjectInherit フラグを指定することもできますが、意味がありません。アクセス制御という目的上、サブキー内の名前と値のペアは別個のオブジェクトにはなっていません。名前と値のペアに対するアクセス権は、サブキーの権限によって制御されます。さらに、すべてのサブキーがコンテナであり、他のサブキーを含めることができるため、ObjectInherit フラグの影響を受けません。また、ObjectInherit フラグを指定すると、互換性がある規則に干渉するため、規則の管理が必要以上に困難になります。 |

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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 プロパティ

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

RegistryAccessRule メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

RegistryAccessRule メンバ
ユーザーまたはグループに許可されたアクセス権セットまたは拒否されたアクセス権セットを表します。このクラスは継承できません。
RegistryAccessRule データ型で公開されるメンバを以下の表に示します。


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

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

- RegistryAccessRuleのページへのリンク