EventWaitHandleAccessRule 类    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示一组允许或拒绝用户或组进行访问的权限。 此类不能被继承。
public ref class EventWaitHandleAccessRule sealed : System::Security::AccessControl::AccessRulepublic sealed class EventWaitHandleAccessRule : System.Security.AccessControl.AccessRule[System.Security.SecurityCritical]
public sealed class EventWaitHandleAccessRule : System.Security.AccessControl.AccessRuletype EventWaitHandleAccessRule = class
    inherit AccessRule[<System.Security.SecurityCritical>]
type EventWaitHandleAccessRule = class
    inherit AccessRulePublic NotInheritable Class EventWaitHandleAccessRule
Inherits AccessRule- 继承
- 属性
示例
下面的代码示例演示如何创建和使用 EventWaitHandleAccessRule 对象。 该示例创建一个 EventWaitHandleSecurity 对象,添加允许和拒绝当前用户的各种权限的规则,并显示生成的规则对。 然后,该示例允许当前用户的新权限并显示结果,显示新权限与现有 Allow 规则合并。
备注
此示例不将安全对象附加到对象 EventWaitHandle 。 可以在其中找到 EventWaitHandle.GetAccessControl 附加安全对象的示例 EventWaitHandle.SetAccessControl。
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) |