EventWaitHandleAccessRule 類別

定義

表示允許或拒絕使用者或群組的一組存取權限。 此類別無法獲得繼承。

public ref class EventWaitHandleAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class EventWaitHandleAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class EventWaitHandleAccessRule : System.Security.AccessControl.AccessRule
type EventWaitHandleAccessRule = class
    inherit AccessRule
[<System.Security.SecurityCritical>]
type EventWaitHandleAccessRule = class
    inherit AccessRule
Public NotInheritable Class EventWaitHandleAccessRule
Inherits AccessRule
繼承
EventWaitHandleAccessRule
屬性

範例

下列程式碼範例示範物件的建立和使用 EventWaitHandleAccessRule 。 此範例會 EventWaitHandleSecurity 建立 物件、新增規則,以允許和拒絕目前使用者的各種許可權,並顯示產生的規則組。 此範例接著會允許目前使用者的新許可權,並顯示結果,顯示新許可權會與現有 Allow 規則合併。

注意

這個範例不會將安全性物件附加至 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.
        EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, 
            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);

        // Add a rule that allows the current user the 
        // right to read permissions on the event. This rule
        // is merged with the existing Allow rule.
        rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.ReadPermissions, 
            AccessControlType.Allow);
        mSec.AddAccessRule(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, Synchronize


Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: Modify, ReadPermissions, 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.
        Dim rule As New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.Synchronize _
            Or EventWaitHandleRights.Modify, _
            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)

        ' Add a rule that allows the current user the 
        ' right to read permissions on the event. This rule
        ' is merged with the existing Allow rule.
        rule = New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.ReadPermissions, _
            AccessControlType.Allow)
        mSec.AddAccessRule(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, Synchronize
'
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: Modify, ReadPermissions, Synchronize

備註

類別 EventWaitHandleAccessRule 是一組類別,.NET Framework提供來管理具名系統事件上的 Windows 存取控制安全性。 如需這些類別的概觀及其與基礎 Windows 存取控制結構的關聯性,請參閱 EventWaitHandleSecurity

注意

Windows 存取控制安全性僅適用于具名系統事件。 EventWaitHandle如果物件代表本機事件,存取控制就不相關。

若要取得目前套用至具名事件的規則清單,請使用 EventWaitHandle.GetAccessControl 方法來取得 EventWaitHandleSecurity 物件,然後使用其 GetAccessRules 方法來取得 物件的集合 EventWaitHandleAccessRule

EventWaitHandleAccessRule 物件不會將一對一對應至基礎任意存取控制清單中的存取控制專案, (DACL) 。 當您取得事件的所有存取規則集合時,此集合包含目前表示所有存取控制專案所需的最小規則數目。

注意

當您套用和移除規則時,基礎存取控制專案會變更。 如果可能的話,規則中的資訊會合並,以維護最少的存取控制專案數目。 因此,當您取得目前的規則清單時,它看起來可能與您所新增的所有規則清單完全相同。

使用 EventWaitHandleAccessRule 物件來指定允許或拒絕使用者或群組的存取權限。 EventWaitHandleAccessRule物件一律代表允許的存取或拒絕存取,絕不會同時代表這兩者。

若要將規則套用至具名系統事件,請使用 EventWaitHandle.GetAccessControl 方法來取得 EventWaitHandleSecurity 物件。 EventWaitHandleSecurity使用方法新增規則來修改物件,然後使用 EventWaitHandle.SetAccessControl 方法重新附加安全性物件。

重要

您對 EventWaitHandleSecurity 物件所做的變更不會影響具名事件的存取層級,直到您呼叫 EventWaitHandle.SetAccessControl 方法,將改變的安全性物件指派給具名事件為止。

EventWaitHandleAccessRule 物件是不可變的。 事件的安全性是使用 類別的 EventWaitHandleSecurity 方法來新增或移除規則來修改;如您所做,會修改基礎存取控制專案。

建構函式

EventWaitHandleAccessRule(IdentityReference, EventWaitHandleRights, AccessControlType)

初始化 EventWaitHandleAccessRule 類別的新執行個體,指定套用此規則的使用者或群組、存取權限,以及允許還是拒絕指定的存取權限。

EventWaitHandleAccessRule(String, EventWaitHandleRights, AccessControlType)

初始化 EventWaitHandleAccessRule 類別的新執行個體,指定套用此規則的使用者或群組名稱、存取權限,以及允許還是拒絕指定的存取權限。

屬性

AccessControlType

取得與這個 AccessControlType 物件相關聯的 AccessRule 值。

(繼承來源 AccessRule)
AccessMask

取得此規則的存取遮罩。

(繼承來源 AuthorizationRule)
EventWaitHandleRights

取得存取規則所允許或拒絕的權限。

IdentityReference

取得要套用此規則的 IdentityReference

(繼承來源 AuthorizationRule)
InheritanceFlags

取得旗標值,這個值會決定子物件繼承這項規則的方式。

(繼承來源 AuthorizationRule)
IsInherited

取得值,表示這個規則是否會明確地設定或繼承自父容器物件。

(繼承來源 AuthorizationRule)
PropagationFlags

取得傳播旗標的值,該值判斷這個規則的繼承如何傳播到子物件。 只有當 InheritanceFlags 列舉的值不是 None,這個屬性才是重要的。

(繼承來源 AuthorizationRule)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱