EventWaitHandleSecurity.RemoveAccessRule(EventWaitHandleAccessRule) メソッド

定義

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

public:
 bool RemoveAccessRule(System::Security::AccessControl::EventWaitHandleAccessRule ^ rule);
public bool RemoveAccessRule (System.Security.AccessControl.EventWaitHandleAccessRule rule);
override this.RemoveAccessRule : System.Security.AccessControl.EventWaitHandleAccessRule -> bool
Public Function RemoveAccessRule (rule As EventWaitHandleAccessRule) As Boolean

パラメーター

rule
EventWaitHandleAccessRule

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

戻り値

互換性のある規則が見つかった場合は true。それ以外の場合は false

例外

rulenullです。

次のコード例では、 メソッドを RemoveAccessRule 使用して オブジェクト内のルールから権限を Allow 削除する方法を EventWaitHandleSecurity 示します。 また、 の他の rule 権限が無視されていることも示しています。

この例では、 オブジェクトを EventWaitHandleSecurity 作成し、現在のユーザーのさまざまな権限を許可および拒否する規則を追加します。 許可される権限には、、ReadPermissions、および がSynchronize含まれますModify。 次に、 と 権限を含むReadPermissionsTakeOwnership現在のユーザーの新しいルールを作成し、 メソッドでそのルールをRemoveAccessRule使用して オブジェクト内EventWaitHandleSecurityAllowルールから削除ReadPermissionsします。 のTakeOwnershiprule右側は無視されます。

Note

この例では、セキュリティ オブジェクトを オブジェクトに EventWaitHandle アタッチしません。 セキュリティ オブジェクトをアタッチする例は、 と EventWaitHandle.SetAccessControlにありますEventWaitHandle.GetAccessControl

using System;
using System.Threading;
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.
        EventWaitHandleSecurity mSec = new EventWaitHandleSecurity();

        // Add a rule that grants the current user the 
        // right to wait on or signal the event and read the
        // permissions on the event.
        EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify
                | EventWaitHandleRights.ReadPermissions, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        // Add a rule that denies the current user the 
        // right to change permissions on the event.
        rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.ChangePermissions, 
            AccessControlType.Deny);
        mSec.AddAccessRule(rule);

        // Display the rules in the security object.
        ShowSecurity(mSec);

        // Create a rule that grants the current user 
        // the right to read permissions on the event, and
        // take ownership of the event. Use this rule to 
        // remove the right to read permissions from the 
        // Allow rule for the current user. The inclusion 
        // of the right to take ownership has no effect.
        rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.TakeOwnership | 
                EventWaitHandleRights.ReadPermissions, 
            AccessControlType.Allow);
        mSec.RemoveAccessRule(rule);

        ShowSecurity(mSec);
    }

    private static void ShowSecurity(EventWaitHandleSecurity security)
    {
        Console.WriteLine("\r\nCurrent access rules:\r\n");

        foreach(EventWaitHandleAccessRule 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.EventWaitHandleRights);
            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: Modify, ReadPermissions, Synchronize


Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: Modify, Synchronize
 */
Imports System.Threading
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 EventWaitHandleSecurity()

        ' Add a rule that grants the current user the 
        ' right to wait on or signal the event, and to 
        ' read its permissions.
        Dim rule As New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.Synchronize _
            Or EventWaitHandleRights.Modify _
            Or EventWaitHandleRights.ReadPermissions, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Add a rule that denies the current user the 
        ' right to change permissions on the event.
        rule = New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.ChangePermissions, _
            AccessControlType.Deny)
        mSec.AddAccessRule(rule)

        ' Display the rules in the security object.
        ShowSecurity(mSec)

        ' Create a rule that grants the current user 
        ' the right to read permissions on the event, and
        ' take ownership of the event. Use this rule to 
        ' remove the right to read permissions from the 
        ' Allow rule for the current user. The inclusion 
        ' of the right to take ownership has no effect.
        rule = New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.TakeOwnership _
            Or EventWaitHandleRights.ReadPermissions, _
            AccessControlType.Allow)
        mSec.RemoveAccessRule(rule)

        ShowSecurity(mSec)
        
    End Sub 

    Private Shared Sub ShowSecurity(ByVal security As EventWaitHandleSecurity)
        Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf)

        For Each ar As EventWaitHandleAccessRule In _
            security.GetAccessRules(True, True, GetType(NTAccount))

            Console.WriteLine("        User: {0}", ar.IdentityReference)
            Console.WriteLine("        Type: {0}", ar.AccessControlType)
            Console.WriteLine("      Rights: {0}", ar.EventWaitHandleRights)
            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: Modify, ReadPermissions, Synchronize
'
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: Modify, Synchronize

注釈

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

重要

イベント アクセス 規則に継承フラグと伝達フラグを指定することはできますが、 メソッドを使用 AccessRuleFactory して作成することで、このフラグを作成することはお勧めしません。 継承と伝達は名前付きイベントに意味を持たないため、アクセス規則のメンテナンスがより複雑になります。

適用対象