RegistrySecurity.RemoveAccessRule メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As RegistrySecurity Dim rule As RegistryAccessRule Dim returnValue As Boolean returnValue = instance.RemoveAccessRule(rule)
- rule
検索対象のユーザーと AccessControlType、および一致する規則が見つかった場合にその規則と互換性のある継承フラグと反映フラグのセットを指定する RegistryAccessRule。互換性のある規則が見つかった場合にその規則から削除する権限を指定します。
互換性のある規則が見つかった場合は true。それ以外の場合は false。


現在の RegistrySecurity で、rule と同じユーザーおよび同じ AccessControlType 値が指定された規則が検索されます。そのような規則が見つからない場合は、何も行われません。メソッドは false を返します。一致する規則が見つかった場合は、規則の継承フラグおよび互換性フラグについて、rule で指定されたフラグとの互換性がチェックされます。互換性のある規則が見つからない場合は、何も行われません。メソッドは false を返します。互換性フラグを含む規則が見つかった場合、rule で指定された規則は互換性のある規則から削除され、メソッドは true を返します。rule が互換性のある規則に含まれていない権限を指定した場合、これらの権限に関する処理は実行されません。互換性のある規則からすべての権限が削除されると、現在の RegistrySecurity オブジェクトから規則全体が削除されます。

RemoveAccessRule メソッドで互換性のある規則から権限を削除する方法と、AddAccessRule メソッドで互換性のある規則に権限をマージする方法を表したコード例を次に示します。
この例では、RegistrySecurity オブジェクトを作成し、現在のユーザーに RegistryRights.ReadKey 権を許可する規則を追加します。さらに、この例では、最初の規則と同じ継承権限と反映権限を使用してユーザーに RegistryRights.SetValue を許可する規則を作成し、RemoveAccessRule メソッドを使用してこの新しい規則を RegistrySecurity オブジェクトから削除します。SetValue は、ReadKey の構成要素です。そのため、互換性のある規則から削除されます。RegistrySecurity オブジェクト内の規則が表示され、ReadKey の残りの構成要素が表示されます。
次に、このプログラム例では、RemoveAccessRule メソッドを呼び出して SetValue 権限を RegistrySecurity オブジェクト内の規則にマージして戻します。
![]() |
---|
この例では、セキュリティ オブジェクトが RegistryKey オブジェクトに割り当てられません。このセクションの 2 つ目の例では、セキュリティ オブジェクトを割り当てます。Microsoft.Win32.RegistryKey.GetAccessControl および RegistryKey.SetAccessControl 内の例も同様です。 |
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() Dim user As String = Environment.UserDomainName _ & "\" & Environment.UserName ' Create a security object that grants no access. Dim mSec As New RegistrySecurity() ' Add a rule that grants the current user ReadKey ' rights. ReadKey is a combination of four other ' rights. The rule is inherited by all ' contained subkeys. Dim rule As New RegistryAccessRule(user, _ RegistryRights.ReadKey, _ InheritanceFlags.ContainerInherit, _ PropagationFlags.None, _ AccessControlType.Allow) mSec.AddAccessRule(rule) ' Create a rule that allows the current user only the ' right to query the key/value pairs of a key, using ' the same inheritance and propagation flags as the ' first rule. QueryValues is a constituent of ' ReadKey, so when this rule is removed, using the ' RemoveAccessRule method, ReadKey is broken into ' its constituent parts. rule = New RegistryAccessRule(user, _ RegistryRights.QueryValues, _ InheritanceFlags.ContainerInherit, _ PropagationFlags.None, _ AccessControlType.Allow) mSec.RemoveAccessRule(rule) ' Display the rules in the security object. ShowSecurity(mSec) ' Add the second rule back. It merges with the ' existing rule, so that the rule is now displayed ' as ReadKey. mSec.AddAccessRule(rule) ' Display the rules in the security object. ShowSecurity(mSec) End Sub Private Shared Sub ShowSecurity(ByVal security As RegistrySecurity) Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf) For Each ar As RegistryAccessRule In _ security.GetAccessRules(True, True, GetType(NTAccount)) Console.WriteLine(" User: {0}", ar.IdentityReference) Console.WriteLine(" Type: {0}", ar.AccessControlType) Console.WriteLine(" Rights: {0}", ar.RegistryRights) Console.WriteLine(" Inheritance: {0}", ar.InheritanceFlags) Console.WriteLine(" Propagation: {0}", ar.PropagationFlags) Console.WriteLine(" Inherited? {0}", ar.IsInherited) Console.WriteLine() Next End Sub End Class 'This code example produces output similar to following: ' 'Current access rules: ' ' User: TestDomain\TestUser ' Type: Allow ' Rights: EnumerateSubKeys, Notify, ReadPermissions ' Inheritance: ContainerInherit ' Propagation: None ' Inherited? False ' ' 'Current access rules: ' ' User: TestDomain\TestUser ' Type: Allow ' Rights: ReadKey ' Inheritance: ContainerInherit ' Propagation: None ' Inherited? False '
using System; using System.Security.AccessControl; using System.Security.Principal; using System.Security; using Microsoft.Win32; public class Example { public static void Main() { string user = Environment.UserDomainName + "\\" + Environment.UserName; // Create a security object that grants no access. RegistrySecurity mSec = new RegistrySecurity(); // Add a rule that grants the current user ReadKey // rights. ReadKey is a combination of four other // rights. The rule is inherited by all // contained subkeys. RegistryAccessRule rule = new RegistryAccessRule(user, RegistryRights.ReadKey, InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow); mSec.AddAccessRule(rule); // Create a rule that allows the current user only the // right to query the key/value pairs of a key, using // the same inheritance and propagation flags as the // first rule. QueryValues is a constituent of // ReadKey, so when this rule is removed, using the // RemoveAccessRule method, ReadKey is broken into // its constituent parts. rule = new RegistryAccessRule(user, RegistryRights.QueryValues, InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow); mSec.RemoveAccessRule(rule); // Display the rules in the security object. ShowSecurity(mSec); // Add the second rule back. It merges with the // existing rule, so that the rule is now displayed // as ReadKey. mSec.AddAccessRule(rule); // Display the rules in the security object. ShowSecurity(mSec); } private static void ShowSecurity(RegistrySecurity security) { Console.WriteLine("\r\nCurrent access rules:\r\n"); foreach( RegistryAccessRule ar in security.GetAccessRules(true, true, typeof(NTAccount)) ) { Console.WriteLine(" User: {0}", ar.IdentityReference); Console.WriteLine(" Type: {0}", ar.AccessControlType); Console.WriteLine(" Rights: {0}", ar.RegistryRights); Console.WriteLine(" Inheritance: {0}", ar.InheritanceFlags); Console.WriteLine(" Propagation: {0}", ar.PropagationFlags); Console.WriteLine(" Inherited? {0}", ar.IsInherited); Console.WriteLine(); } } } /* This code example produces output similar to following: Current access rules: User: TestDomain\TestUser Type: Allow Rights: EnumerateSubKeys, Notify, ReadPermissions Inheritance: ContainerInherit Propagation: None Inherited? False Current access rules: User: TestDomain\TestUser Type: Allow Rights: ReadKey Inheritance: ContainerInherit Propagation: None Inherited? False */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からRegistrySecurity.RemoveAccessRule メソッドを検索する場合は、下記のリンクをクリックしてください。

- RegistrySecurity.RemoveAccessRule メソッドのページへのリンク