Attempt to use RemoveAccessRuleSpecific on the original rule : RemoveAccessRuleSpecific « Security « C# / CSharp Tutorial






using System;
using System.Threading;
using System.Security.AccessControl;
using System.Security.Principal;

public class Example
{
    public static void Main()
    {
        string user = Environment.UserDomainName + "\\" + Environment.UserName;
        MutexSecurity mSec = new MutexSecurity();
        MutexAccessRule ruleA = new MutexAccessRule(user,MutexRights.Synchronize | MutexRights.Modify,AccessControlType.Allow);
        mSec.AddAccessRule(ruleA);


        MutexAccessRule rule = new MutexAccessRule(user,MutexRights.ReadPermissions,AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        mSec.RemoveAccessRuleSpecific(ruleA);

        foreach(MutexAccessRule ar in mSec.GetAccessRules(true, true, typeof(NTAccount)))
        {
            Console.WriteLine("User: {0}", ar.IdentityReference);
            Console.WriteLine("Type: {0}", ar.AccessControlType);
            Console.WriteLine("Rights: {0}", ar.MutexRights);
        }
    }
}








35.24.RemoveAccessRuleSpecific
35.24.1.Use RemoveAccessRuleSpecific with the correct rights
35.24.2.Attempt to use RemoveAccessRuleSpecific on the original rule