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.
        MutexSecurity mSec = new MutexSecurity();

        // Add a rule that grants the current user the
        // right to enter or release the mutex and read the
        // permissions on the mutex.
        MutexAccessRule rule = new MutexAccessRule(user,
                                                   MutexRights.Synchronize | MutexRights.Modify
                                                   | MutexRights.ReadPermissions,
                                                   AccessControlType.Allow);

        mSec.AddAccessRule(rule);

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

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

        // Create a rule that grants the current user
        // the full control over the mutex. Use the
        // ResetAccessRule method to replace both of
        // the existing rules with the new rule.
        rule = new MutexAccessRule(user,
                                   MutexRights.FullControl,
                                   AccessControlType.Allow);
        mSec.ResetAccessRule(rule);

        ShowSecurity(mSec);
    }