FileSystemSecurity.RemoveAccessRule(FileSystemAccessRule) Método

Definição

Remove do diretório ou arquivo atual todas as permissões de negar ou permitir da ACL (lista de controle de acesso) que forem correspondentes.Removes all matching allow or deny access control list (ACL) permissions from the current file or directory.

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

Parâmetros

rule
FileSystemAccessRule

Um objeto FileSystemAccessRule que representa uma permissão da ACL (lista de controle de acesso) a ser removida de um arquivo ou diretório.A FileSystemAccessRule object that represents an access control list (ACL) permission to remove from a file or directory.

Retornos

Boolean

true se a regra de acesso tiver sido removida; caso contrário, false.true if the access rule was removed; otherwise, false.

Exceções

O parâmetro rule é null.The rule parameter is null.

Exemplos

O exemplo de código a seguir usa a FileSecurity classe para adicionar e, em seguida, remover uma entrada de lista de controle de acesso (ACL) de um arquivo.The following code example uses the FileSecurity class to add and then remove an access control list (ACL) entry from a file. Você deve fornecer uma conta de grupo ou de usuário válida para executar este exemplo.You must supply a valid user or group account to run this example.

using namespace System;
using namespace System::IO;
using namespace System::Security::AccessControl;

// Adds an ACL entry on the specified file for the specified account.

void AddFileSecurity(String^ fileName, String^ account, 
                        FileSystemRights rights, AccessControlType controlType)
{
    // Get a FileSecurity object that represents the 
    // current security settings.
    FileSecurity^ fSecurity = File::GetAccessControl(fileName);

    // Add the FileSystemAccessRule to the security settings. 
    fSecurity->AddAccessRule(gcnew FileSystemAccessRule
                                   (account,rights, controlType));

    // Set the new access settings.
    File::SetAccessControl(fileName, fSecurity);
}

// Removes an ACL entry on the specified file for the specified account.

void RemoveFileSecurity(String^ fileName, String^ account, 
                        FileSystemRights rights, AccessControlType controlType)
{

    // Get a FileSecurity object that represents the 
    // current security settings.
    FileSecurity^ fSecurity = File::GetAccessControl(fileName);

    // Remove the FileSystemAccessRule from the security settings. 
    fSecurity->RemoveAccessRule(gcnew FileSystemAccessRule
                                      (account,rights, controlType));

    // Set the new access settings.
    File::SetAccessControl(fileName, fSecurity);
}

int main()
{
    try
    {
        String^ fileName = "test.xml";

        Console::WriteLine("Adding access control entry for " + fileName);

        // Add the access control entry to the file.
        AddFileSecurity(fileName, "MYDOMAIN\\MyAccount", 
            FileSystemRights::ReadData, AccessControlType::Allow);

        Console::WriteLine("Removing access control entry from " + fileName);

        // Remove the access control entry from the file.
        RemoveFileSecurity(fileName, "MYDOMAIN\\MyAccount", 
            FileSystemRights::ReadData, AccessControlType::Allow);

        Console::WriteLine("Done.");
    }
    catch (Exception^ ex)
    {
        Console::WriteLine(ex->Message);
    }
}

using System;
using System.IO;
using System.Security.AccessControl;

namespace FileSystemExample
{
    class FileExample
    {
        public static void Main()
        {
            try
            {
                string fileName = "test.xml";

                Console.WriteLine("Adding access control entry for "
                    + fileName);

                // Add the access control entry to the file.
                AddFileSecurity(fileName, @"DomainName\AccountName",
                    FileSystemRights.ReadData, AccessControlType.Allow);

                Console.WriteLine("Removing access control entry from "
                    + fileName);

                // Remove the access control entry from the file.
                RemoveFileSecurity(fileName, @"DomainName\AccountName",
                    FileSystemRights.ReadData, AccessControlType.Allow);

                Console.WriteLine("Done.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

        // Adds an ACL entry on the specified file for the specified account.
        public static void AddFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Add the FileSystemAccessRule to the security settings.
            fSecurity.AddAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);
        }

        // Removes an ACL entry on the specified file for the specified account.
        public static void RemoveFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Remove the FileSystemAccessRule from the security settings.
            fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);
        }
    }
}
Imports System.IO
Imports System.Security.AccessControl



Module FileExample

    Sub Main()
        Try
            Dim fileName As String = "test.xml"

            Console.WriteLine("Adding access control entry for " & fileName)

            ' Add the access control entry to the file.
            AddFileSecurity(fileName, "DomainName\AccountName", _
                FileSystemRights.ReadData, AccessControlType.Allow)

            Console.WriteLine("Removing access control entry from " & fileName)

            ' Remove the access control entry from the file.
            RemoveFileSecurity(fileName, "DomainName\AccountName", _
                FileSystemRights.ReadData, AccessControlType.Allow)

            Console.WriteLine("Done.")
        Catch e As Exception
            Console.WriteLine(e)
        End Try

    End Sub


    ' Adds an ACL entry on the specified file for the specified account.
    Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, _
        ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)
  
        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

        ' Add the FileSystemAccessRule to the security settings. 
        Dim accessRule As FileSystemAccessRule = _
            New FileSystemAccessRule(account, rights, controlType)

        fSecurity.AddAccessRule(accessRule)

        ' Set the new access settings.
        File.SetAccessControl(fileName, fSecurity)

    End Sub


    ' Removes an ACL entry on the specified file for the specified account.
    Sub RemoveFileSecurity(ByVal fileName As String, ByVal account As String, _
        ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)

        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

        ' Remove the FileSystemAccessRule from the security settings. 
        fSecurity.RemoveAccessRule(New FileSystemAccessRule(account, _
            rights, controlType))

        ' Set the new access settings.
        File.SetAccessControl(fileName, fSecurity)

    End Sub
End Module

Comentários

O RemoveAccessRule método remove todas as Deny regras de acesso correspondentes ou todas as Allow regras de acesso correspondentes do FileSystemSecurity objeto atual.The RemoveAccessRule method removes either all matching Deny access rules or all matching Allow access rules from the current FileSystemSecurity object. Por exemplo, você pode usar esse método para remover todas as Deny regras de acesso de um usuário, passando um FileSystemAccessRule objeto criado usando o Deny valor, o Read valor e uma conta de usuário.For example, you can use this method to remove all Deny access rules for a user by passing a FileSystemAccessRule object created using the Deny value, the Read value, and a user account. Quando você faz isso, o RemoveAccessRule método remove todas as regras Deny que especificam o Read valor ou o Write valor.When you do this, the RemoveAccessRule method removes any deny rules that specify the Read value or the Write value.

Para persistir informações de lista de controle de acesso (ACL) novas ou alteradas para um arquivo, use o SetAccessControl SetAccessControl método ou.To persist new or changed access control list (ACL) information to a file, use the SetAccessControl or SetAccessControl method. Para persistir informações de ACL novas ou alteradas para um diretório, use o SetAccessControl SetAccessControl método ou.To persist new or changed ACL information to a directory, use the SetAccessControl or SetAccessControl method.

Para recuperar informações de ACL de um arquivo, use GetAccessControl o GetAccessControl método ou.To retrieve ACL information from a file, use the GetAccessControl or GetAccessControl method. Para recuperar informações de ACL de um diretório, use GetAccessControl o GetAccessControl método ou.To retrieve ACL information from a directory, use the GetAccessControl or GetAccessControl method.

Quando você adiciona uma regra de acesso sem definir o Synchronize sinalizador, o Synchronize sinalizador será adicionado automaticamente à sua regra.When you add an access rule without setting the Synchronize flag, the Synchronize flag will be automatically added to your rule. Se você remover a regra mais tarde sem especificar o Synchronize sinalizador, o sinalizador será removido automaticamente.If you remove the rule later without specifying the Synchronize flag, the flag will automatically be removed.

Aplica-se a