SemaphoreSecurity.RemoveAccessRule(SemaphoreAccessRule) SemaphoreSecurity.RemoveAccessRule(SemaphoreAccessRule) SemaphoreSecurity.RemoveAccessRule(SemaphoreAccessRule) SemaphoreSecurity.RemoveAccessRule(SemaphoreAccessRule) Method

Définition

Recherche une règle de contrôle d'accès ayant les mêmes utilisateur et AccessControlType (autorisation ou refus) que la règle spécifiée et ayant des indicateurs d'héritage et de propagation compatibles ; si une telle règle est trouvée, les droits contenus dans la règle d'accès spécifiée en sont supprimés.Searches for an access control rule with the same user and AccessControlType (allow or deny) as the specified rule, and with compatible inheritance and propagation flags; if such a rule is found, the rights contained in the specified access rule are removed from it.

public:
 bool RemoveAccessRule(System::Security::AccessControl::SemaphoreAccessRule ^ rule);
public bool RemoveAccessRule (System.Security.AccessControl.SemaphoreAccessRule rule);
override this.RemoveAccessRule : System.Security.AccessControl.SemaphoreAccessRule -> bool
Public Function RemoveAccessRule (rule As SemaphoreAccessRule) As Boolean

Paramètres

rule
SemaphoreAccessRule SemaphoreAccessRule SemaphoreAccessRule SemaphoreAccessRule

SemaphoreAccessRule qui spécifie l'utilisateur et AccessControlType à rechercher, ainsi qu'un jeu d'indicateurs d'héritage et de propagation avec lesquels une règle correspondante, si elle est trouvée, doit être compatible.A SemaphoreAccessRule that specifies the user and AccessControlType to search for, and a set of inheritance and propagation flags that a matching rule, if found, must be compatible with. Spécifie les droits à supprimer de la règle compatible, le cas échéant.Specifies the rights to remove from the compatible rule, if found.

Retours

true si une règle compatible est trouvée ; sinon, false.true if a compatible rule is found; otherwise false.

Exceptions

Exemples

L’exemple de code suivant illustre l’utilisation de RemoveAccessRule la méthode pour supprimer les droits Allow d’une règle SemaphoreSecurity dans un objet.The following code example demonstrates the use of the RemoveAccessRule method to remove rights from an Allow rule in a SemaphoreSecurity object. Il montre également que les autres droits rule dans sont ignorés.It also shows that other rights in rule are ignored.

L’exemple crée un SemaphoreSecurity objet et ajoute des règles qui autorisent et refusent divers droits pour l’utilisateur actuel.The example creates a SemaphoreSecurity object and adds rules that allow and deny various rights for the current user. Les droits autorisés sont Modifyles ReadPermissionssuivants: Synchronize, et.The rights allowed include Modify, ReadPermissions, and Synchronize. L’exemple crée ensuite une nouvelle règle pour l’utilisateur actuel, y ReadPermissions compris TakeOwnership les droits et, et utilise cette règle RemoveAccessRule avec la méthode ReadPermissions pour supprimer Allow de la règle SemaphoreSecurity dans l’objet.The example then creates a new rule for the current user, including ReadPermissions and TakeOwnership rights, and uses that rule with the RemoveAccessRule method to remove ReadPermissions from the Allow rule in the SemaphoreSecurity object. Le TakeOwnership droit superflu dans rule est ignoré.The extraneous TakeOwnership right in rule is ignored.

Notes

Cet exemple n’attache pas l’objet de sécurité à Semaphore un objet.This example does not attach the security object to a Semaphore object. Des exemples qui attachent des objets de sécurité Semaphore.GetAccessControl sont Semaphore.SetAccessControldisponibles dans et.Examples that attach security objects can be found in Semaphore.GetAccessControl and Semaphore.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.
        SemaphoreSecurity mSec = new SemaphoreSecurity();

        // Add a rule that grants the current user the 
        // right to enter or release the semaphore and read the
        // permissions on the semaphore.
        SemaphoreAccessRule rule = new SemaphoreAccessRule(user, 
            SemaphoreRights.Synchronize | SemaphoreRights.Modify
                | SemaphoreRights.ReadPermissions, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

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

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

        // Create a rule that grants the current user 
        // the right to read permissions on the semaphore, and
        // take ownership of the semaphore. Use this rule to 
        // remove the right to read permissions from the 
        // Allow rule for the current user. The inclusion 
        // of the right to take ownership has no effect.
        rule = new SemaphoreAccessRule(user, 
            SemaphoreRights.TakeOwnership | 
                SemaphoreRights.ReadPermissions, 
            AccessControlType.Allow);
        mSec.RemoveAccessRule(rule);

        ShowSecurity(mSec);
    }

    private static void ShowSecurity(SemaphoreSecurity security)
    {
        Console.WriteLine("\r\nCurrent access rules:\r\n");

        foreach(SemaphoreAccessRule 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.SemaphoreRights);
            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, ReadPermissions, Synchronize


Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: Modify, 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 SemaphoreSecurity()

        ' Add a rule that grants the current user the 
        ' right to enter or release the semaphore, and to 
        ' read its permissions.
        Dim rule As New SemaphoreAccessRule(user, _
            SemaphoreRights.Synchronize _
            Or SemaphoreRights.Modify _
            Or SemaphoreRights.ReadPermissions, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Add a rule that denies the current user the 
        ' right to change permissions on the semaphore.
        rule = New SemaphoreAccessRule(user, _
            SemaphoreRights.ChangePermissions, _
            AccessControlType.Deny)
        mSec.AddAccessRule(rule)

        ' Display the rules in the security object.
        ShowSecurity(mSec)

        ' Create a rule that grants the current user 
        ' the right to read permissions on the semaphore, and
        ' take ownership of the semaphore. Use this rule to 
        ' remove the right to read permissions from the 
        ' Allow rule for the current user. The inclusion 
        ' of the right to take ownership has no effect.
        rule = New SemaphoreAccessRule(user, _
            SemaphoreRights.TakeOwnership _
            Or SemaphoreRights.ReadPermissions, _
            AccessControlType.Allow)
        mSec.RemoveAccessRule(rule)

        ShowSecurity(mSec)
        
    End Sub 

    Private Shared Sub ShowSecurity(ByVal security As SemaphoreSecurity)
        Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf)

        For Each ar As SemaphoreAccessRule In _
            security.GetAccessRules(True, True, GetType(NTAccount))

            Console.WriteLine("        User: {0}", ar.IdentityReference)
            Console.WriteLine("        Type: {0}", ar.AccessControlType)
            Console.WriteLine("      Rights: {0}", ar.SemaphoreRights)
            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, ReadPermissions, Synchronize
'
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: Modify, Synchronize

Remarques

Une règle SemaphoreSecurity ayant le même utilisateur et la même AccessControlType valeur que rule. est recherchée dans le en cours.The current SemaphoreSecurity is searched for a rule that has the same user and the same AccessControlType value as rule. Si aucune règle de ce type n’est trouvée, aucune action n’est effectuée et falsela méthode retourne.If no such rule is found, no action is taken, and the method returns false. Si des règles de correspondance sont trouvées, leurs indicateurs d’héritage et de compatibilité sont vérifiés pour la rulecompatibilité avec les indicateurs spécifiés dans.If matching rules are found, their inheritance and compatibility flags are checked for compatibility with the flags specified in rule. Si aucune règle compatible n’est trouvée, aucune action n’est effectuée et la méthode falseretourne.If no compatible rule is found, no action is taken, and the method returns false. Si une règle avec des indicateurs compatibles est trouvée, les droits spécifiés dans rule sont supprimés de la règle compatible et la méthode retourne. trueIf a rule with compatible flags is found, the rights specified in rule are removed from the compatible rule, and the method returns true. Si rule spécifie des droits non contenus dans la règle compatible, aucune action n’est entreprise en ce qui concerne ces droits.If rule specifies rights not contained in the compatible rule, no action is taken with respect to those rights. Si tous les droits sont supprimés de la règle compatible, toute la règle est supprimée de SemaphoreSecurity l’objet actuel.If all rights are removed from the compatible rule, the entire rule is removed from the current SemaphoreSecurity object.

Important

Bien que vous puissiez spécifier des indicateurs d’héritage et de propagation pour les règles d’accès sémaphore, AccessRuleFactory en les créant avec la méthode, cela n’est pas recommandé.Although you can specify inheritance and propagation flags for semaphore access rules, by creating them with the AccessRuleFactory method, this is not recommended. L’héritage et la propagation n’ont aucune signification pour les sémaphores nommés, et ils rendent la maintenance des règles d’accès plus complexe.Inheritance and propagation have no meaning for named semaphores, and they make the maintenance of access rules more complicated.

S’applique à