FileSystemAccessRule Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy FileSystemAccessRule.

Przeciążenia

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu odwołania do konta użytkownika, wartość określającą typ operacji skojarzonej z regułą dostępu oraz wartość określającą, czy zezwolić na operację, czy jej odmówić.

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu nazwy konta użytkownika, wartości określającej typ operacji skojarzonej z regułą dostępu oraz wartość opisujący, czy zezwolić na operację, czy jej odmówić.

FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu odwołania do konta użytkownika, wartość określającą typ operacji skojarzonej z regułą dostępu, wartość określającą sposób dziedziczenia praw, wartość określającą sposób propagacji praw oraz wartość określającą, czy mają być propagowane prawa, czy też odmawiać operacji.

FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu nazwy konta użytkownika, wartości, która określa typ operacji skojarzonej z regułą dostępu, wartość określającą sposób dziedziczenia praw, wartość określającą sposób propagacji praw oraz wartość określającą, czy mają być propagowane prawa, oraz wartość określającą, czy zezwolić na operację, czy jej odmówić.

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu odwołania do konta użytkownika, wartość określającą typ operacji skojarzonej z regułą dostępu oraz wartość określającą, czy zezwolić na operację, czy jej odmówić.

public:
 FileSystemAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, type As AccessControlType)

Parametry

identity
IdentityReference

IdentityReference Obiekt, który hermetyzuje odwołanie do konta użytkownika.

fileSystemRights
FileSystemRights

FileSystemRights Jedna z wartości określających typ operacji skojarzonej z regułą dostępu.

type
AccessControlType

AccessControlType Jedną z wartości określających, czy zezwolić na operację, czy odmówić jej.

Wyjątki

Parametr identity nie jest obiektem IdentityReference .

Parametr identity to null.

Do parametru type przekazano niepoprawne wyliczenie.

Uwagi

Użyj tego konstruktora, aby utworzyć regułę kontroli dostępu, którą można utrwalać przy użyciu FileSecurity klasy or DirectorySecurity . Reguły kontroli dostępu definiują prawa konta użytkownika, które określają, które akcje są dozwolone lub niedozwolone na komputerach z systemem Microsoft Windows.

Dotyczy

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu nazwy konta użytkownika, wartości określającej typ operacji skojarzonej z regułą dostępu oraz wartość opisujący, czy zezwolić na operację, czy jej odmówić.

public:
 FileSystemAccessRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, type As AccessControlType)

Parametry

identity
String

Nazwa konta użytkownika.

fileSystemRights
FileSystemRights

FileSystemRights Jedna z wartości określających typ operacji skojarzonej z regułą dostępu.

type
AccessControlType

AccessControlType Jedną z wartości określających, czy zezwolić na operację, czy odmówić jej.

Wyjątki

Parametr identity to null.

Do parametru type przekazano niepoprawne wyliczenie.

Przykłady

Poniższy przykład kodu używa klasy do dodania FileSecurity , a następnie usunięcia wpisu kontroli dostępu (ACE) z pliku. Aby uruchomić ten przykład, musisz podać prawidłowe konto użytkownika lub grupy.

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

Uwagi

Użyj tego konstruktora, aby utworzyć regułę kontroli dostępu, którą można utrwalać przy użyciu FileSecurity klasy or DirectorySecurity . Reguły kontroli dostępu definiują prawa konta użytkownika, które określają, które akcje są dozwolone lub niedozwolone na komputerach z systemem Microsoft Windows.

Parametr identity musi zidentyfikować prawidłowe konto na bieżącym komputerze lub domenie. Ciąg ma następującą formę, gdzie DOMAIN jest nazwą prawidłowej domeny lub nazwy komputera i account jest nazwą prawidłowego konta użytkownika w domenie lub komputerze: DOMAIN\account.

Dotyczy

FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu odwołania do konta użytkownika, wartość określającą typ operacji skojarzonej z regułą dostępu, wartość określającą sposób dziedziczenia praw, wartość określającą sposób propagacji praw oraz wartość określającą, czy mają być propagowane prawa, czy też odmawiać operacji.

public:
 FileSystemAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, type As AccessControlType)

Parametry

identity
IdentityReference

IdentityReference Obiekt, który hermetyzuje odwołanie do konta użytkownika.

fileSystemRights
FileSystemRights

FileSystemRights Jedna z wartości określających typ operacji skojarzonej z regułą dostępu.

inheritanceFlags
InheritanceFlags

InheritanceFlags Jedna z wartości określających sposób propagacji masek dostępu do obiektów podrzędnych.

propagationFlags
PropagationFlags

PropagationFlags Jedna z wartości określających sposób propagacji Access Control wpisów (ACE) do obiektów podrzędnych.

type
AccessControlType

AccessControlType Jedną z wartości określających, czy zezwolić na operację, czy odmówić jej.

Wyjątki

Parametr identity nie jest obiektem IdentityReference .

Parametr identity to null.

Do parametru type przekazano niepoprawne wyliczenie.

-lub-

Do parametru inheritanceFlags przekazano niepoprawne wyliczenie.

-lub-

Do parametru propagationFlags przekazano niepoprawne wyliczenie.

Uwagi

Użyj tego konstruktora, aby utworzyć regułę kontroli dostępu, którą można utrwalać przy użyciu FileSecurity klasy or DirectorySecurity . Reguły kontroli dostępu definiują prawa konta użytkownika, które określają, które akcje są dozwolone lub niedozwolone na komputerach z systemem Microsoft Windows.

Dotyczy

FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu nazwy konta użytkownika, wartości, która określa typ operacji skojarzonej z regułą dostępu, wartość określającą sposób dziedziczenia praw, wartość określającą sposób propagacji praw oraz wartość określającą, czy mają być propagowane prawa, oraz wartość określającą, czy zezwolić na operację, czy jej odmówić.

public:
 FileSystemAccessRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, type As AccessControlType)

Parametry

identity
String

Nazwa konta użytkownika.

fileSystemRights
FileSystemRights

FileSystemRights Jedna z wartości określających typ operacji skojarzonej z regułą dostępu.

inheritanceFlags
InheritanceFlags

InheritanceFlags Jedna z wartości określających sposób propagacji masek dostępu do obiektów podrzędnych.

propagationFlags
PropagationFlags

PropagationFlags Jedna z wartości określających sposób propagacji Access Control wpisów (ACE) do obiektów podrzędnych.

type
AccessControlType

AccessControlType Jedną z wartości określających, czy zezwolić na operację, czy odmówić jej.

Wyjątki

Parametr identity to null.

Do parametru type przekazano niepoprawne wyliczenie.

-lub-

Do parametru inheritanceFlags przekazano niepoprawne wyliczenie.

-lub-

Do parametru propagationFlags przekazano niepoprawne wyliczenie.

Uwagi

Użyj tego konstruktora, aby utworzyć regułę kontroli dostępu, którą można utrwalać przy użyciu FileSecurity klasy or DirectorySecurity . Reguły kontroli dostępu definiują prawa konta użytkownika, które określają, które akcje są dozwolone lub niedozwolone na komputerach z systemem Microsoft Windows.

Parametr identity musi zidentyfikować prawidłowe konto na bieżącym komputerze lub domenie. Ciąg ma następującą formę, gdzie DOMAIN jest nazwą prawidłowej domeny lub nazwy komputera i account jest nazwą prawidłowego konta użytkownika w domenie lub komputerze: DOMAIN\account.

Dotyczy