本文整理汇总了C#中System.Security.AccessControl.MutexSecurity.RemoveAccessRuleSpecific方法的典型用法代码示例。如果您正苦于以下问题:C# MutexSecurity.RemoveAccessRuleSpecific方法的具体用法?C# MutexSecurity.RemoveAccessRuleSpecific怎么用?C# MutexSecurity.RemoveAccessRuleSpecific使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.AccessControl.MutexSecurity
的用法示例。
在下文中一共展示了MutexSecurity.RemoveAccessRuleSpecific方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanSetAndGetMutexSecurity
public void CanSetAndGetMutexSecurity ()
{
if (PlatformID.Win32NT != Environment.OSVersion.Platform) {
Assert.Ignore (); return;
}
MutexAccessRule rule; SecurityIdentifier sid;
AuthorizationRuleCollection rulesA, rulesB, rulesC;
bool createdNew; MutexSecurity security;
string name = @"Local\MonoTestMutex";
using (Mutex mutex = new Mutex(false, name, out createdNew)) {
Assert.IsTrue (createdNew);
security = mutex.GetAccessControl ();
rulesA = security.GetAccessRules (true, false, typeof (SecurityIdentifier));
Assert.AreNotEqual (0, rulesA.Count);
// Contrary to what you'd expect, these classes only try to persist sections that
// that were *changed*. Awful, eh? To be fair, if you retrieve and modify it's fine.
security = new MutexSecurity ();
mutex.SetAccessControl (security);
security = mutex.GetAccessControl ();
rulesB = security.GetAccessRules (true, false, typeof (SecurityIdentifier));
Assert.AreEqual (rulesA.Count, rulesB.Count);
// And here's our dummy change. Observe...
sid = new SecurityIdentifier( "S-1-5-12-3456-7890");
rule = new MutexAccessRule (sid, MutexRights.Synchronize, AccessControlType.Allow);
security = new MutexSecurity ();
security.RemoveAccessRuleSpecific (rule);
mutex.SetAccessControl (security);
security = mutex.GetAccessControl ();
rulesC = security.GetAccessRules (true, false, typeof (SecurityIdentifier));
Assert.AreEqual (0, rulesC.Count);
}
}