RegistrySecurity.RemoveAccessRule メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > RegistrySecurity.RemoveAccessRule メソッドの意味・解説 

RegistrySecurity.RemoveAccessRule メソッド

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

指定したアクセス規則と同じユーザーAccessControlType (許可または拒否)、および互換性のある継承フラグ反映フラグ指定されアクセス制御規則検索されます。このような規則が見つかると、指定したアクセス規則含まれる権限がその規則から削除されます。

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

Public Function RemoveAccessRule ( _
    rule As RegistryAccessRule _
) As Boolean
Dim instance As RegistrySecurity
Dim rule As RegistryAccessRule
Dim returnValue As Boolean

returnValue = instance.RemoveAccessRule(rule)
public bool RemoveAccessRule (
    RegistryAccessRule rule
)
public:
bool RemoveAccessRule (
    RegistryAccessRule^ rule
)
public boolean RemoveAccessRule (
    RegistryAccessRule rule
)
public function RemoveAccessRule (
    rule : RegistryAccessRule
) : boolean

パラメータ

rule

検索対象ユーザーと AccessControlType、および一致する規則見つかった場合にその規則互換性のある継承フラグ反映フラグセット指定する RegistryAccessRule。互換性のある規則見つかった場合にその規則から削除する権限指定します

戻り値
互換性のある規則見つかった場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

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

解説解説
使用例使用例

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



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

辞書ショートカット

すべての辞書の索引

RegistrySecurity.RemoveAccessRule メソッドのお隣キーワード
検索ランキング

   

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



RegistrySecurity.RemoveAccessRule メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS