FileSystemAccessRule 构造函数

定义

初始化 FileSystemAccessRule 类的新实例。Initializes a new instance of the FileSystemAccessRule class.

重载

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

使用以下内容初始化 FileSystemAccessRule 类的新实例:对用户帐户的引用、指定与访问规则关联的操作的类型的值,以及指定是允许还是拒绝该操作的值。Initializes a new instance of the FileSystemAccessRule class using a reference to a user account, a value that specifies the type of operation associated with the access rule, and a value that specifies whether to allow or deny the operation.

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

使用以下内容初始化 FileSystemAccessRule 类的新实例:用户帐户的名称、指定与访问规则关联的操作的类型的值,以及描述是允许还是拒绝该操作的值。Initializes a new instance of the FileSystemAccessRule class using the name of a user account, a value that specifies the type of operation associated with the access rule, and a value that describes whether to allow or deny the operation.

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

使用以下内容初始化 FileSystemAccessRule 类的新实例:对用户帐户的引用、指定与访问规则关联的操作的类型的值、确定如何继承权限的值、确定如何传播权限的值,以及指定是允许还是拒绝该操作的值。Initializes a new instance of the FileSystemAccessRule class using a reference to a user account, a value that specifies the type of operation associated with the access rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies whether to allow or deny the operation.

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

使用以下内容初始化 FileSystemAccessRule 类的新实例:用户帐户的名称、指定与访问规则关联的操作的类型的值、确定如何继承权限的值、确定如何传播权限的值,以及指定是允许还是拒绝该操作的值。Initializes a new instance of the FileSystemAccessRule class using the name of a user account, a value that specifies the type of operation associated with the access rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies whether to allow or deny the operation.

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

使用以下内容初始化 FileSystemAccessRule 类的新实例:对用户帐户的引用、指定与访问规则关联的操作的类型的值,以及指定是允许还是拒绝该操作的值。Initializes a new instance of the FileSystemAccessRule class using a reference to a user account, a value that specifies the type of operation associated with the access rule, and a value that specifies whether to allow or deny the operation.

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)

参数

identity
IdentityReference

封装对用户帐户的引用的 IdentityReference 对象。An IdentityReference object that encapsulates a reference to a user account.

fileSystemRights
FileSystemRights

FileSystemRights 值之一,该值指定与访问规则关联的操作的类型。One of the FileSystemRights values that specifies the type of operation associated with the access rule.

type
AccessControlType

AccessControlType 值之一,该值指定是允许还是拒绝该操作。One of the AccessControlType values that specifies whether to allow or deny the operation.

例外

identity 参数不是一个 IdentityReference 对象。The identity parameter is not an IdentityReference object.

identity 参数为 nullThe identity parameter is null.

一个错误枚举被传递给 type 参数。An incorrect enumeration was passed to the type parameter.

注解

使用此构造函数创建一个可以使用或类持久保存的访问控制 FileSecurity 规则 DirectorySecurityUse this constructor to create an access control rule that you can persist using the FileSecurity or DirectorySecurity class. 访问控制规则定义用户帐户权限,以确定在运行 Microsoft Windows 的计算机上允许或禁止的操作。Access control rules define user account rights that determine which actions are allowed or disallowed on computers running Microsoft Windows.

适用于

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

使用以下内容初始化 FileSystemAccessRule 类的新实例:用户帐户的名称、指定与访问规则关联的操作的类型的值,以及描述是允许还是拒绝该操作的值。Initializes a new instance of the FileSystemAccessRule class using the name of a user account, a value that specifies the type of operation associated with the access rule, and a value that describes whether to allow or deny the operation.

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)

参数

identity
String

用户帐户的名称。The name of a user account.

fileSystemRights
FileSystemRights

FileSystemRights 值之一,该值指定与访问规则关联的操作的类型。One of the FileSystemRights values that specifies the type of operation associated with the access rule.

type
AccessControlType

AccessControlType 值之一,该值指定是允许还是拒绝该操作。One of the AccessControlType values that specifies whether to allow or deny the operation.

例外

identity 参数为 nullThe identity parameter is null.

一个错误枚举被传递给 type 参数。An incorrect enumeration was passed to the type parameter.

示例

下面的代码示例使用 FileSecurity 类从文件中添加 (ACE) 的访问控制项,然后将其移除。The following code example uses the FileSecurity class to add and then remove an access control entry (ACE) from a file. 你必须提供有效的用户或组帐户以运行此示例。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

注解

使用此构造函数创建一个可以使用或类持久保存的访问控制 FileSecurity 规则 DirectorySecurityUse this constructor to create an access control rule that you can persist using the FileSecurity or DirectorySecurity class. 访问控制规则定义用户帐户权限,以确定在运行 Microsoft Windows 的计算机上允许或禁止的操作。Access control rules define user account rights that determine which actions are allowed or disallowed on computers running Microsoft Windows.

identity参数必须标识当前计算机或域上的有效帐户。The identity parameter must identify a valid account on the current computer or domain. 此字符串采用以下形式,其中 DOMAIN 是有效域或计算机名称的名称, account 是域或计算机上有效用户帐户的名称: DOMAIN\accountThe string takes the following form, where DOMAIN is the name of a valid domain or computer name and account is the name of a valid user account on a domain or computer: DOMAIN\account.

适用于

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

使用以下内容初始化 FileSystemAccessRule 类的新实例:对用户帐户的引用、指定与访问规则关联的操作的类型的值、确定如何继承权限的值、确定如何传播权限的值,以及指定是允许还是拒绝该操作的值。Initializes a new instance of the FileSystemAccessRule class using a reference to a user account, a value that specifies the type of operation associated with the access rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies whether to allow or deny the operation.

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)

参数

identity
IdentityReference

封装对用户帐户的引用的 IdentityReference 对象。An IdentityReference object that encapsulates a reference to a user account.

fileSystemRights
FileSystemRights

FileSystemRights 值之一,该值指定与访问规则关联的操作的类型。One of the FileSystemRights values that specifies the type of operation associated with the access rule.

inheritanceFlags
InheritanceFlags

InheritanceFlags 值之一,该值指定访问掩码如何传播到子对象。One of the InheritanceFlags values that specifies how access masks are propagated to child objects.

propagationFlags
PropagationFlags

PropagationFlags 值之一,该值指定访问控制项 (ACE) 如何传播到子对象。One of the PropagationFlags values that specifies how Access Control Entries (ACEs) are propagated to child objects.

type
AccessControlType

AccessControlType 值之一,该值指定是允许还是拒绝该操作。One of the AccessControlType values that specifies whether to allow or deny the operation.

例外

identity 参数不是一个 IdentityReference 对象。The identity parameter is not an IdentityReference object.

identity 参数为 nullThe identity parameter is null.

一个错误枚举被传递给 type 参数。An incorrect enumeration was passed to the type parameter.

- 或 --or- 一个错误枚举被传递给 inheritanceFlags 参数。An incorrect enumeration was passed to the inheritanceFlags parameter.

- 或 --or- 一个错误枚举被传递给 propagationFlags 参数。An incorrect enumeration was passed to the propagationFlags parameter.

注解

使用此构造函数创建一个可以使用或类持久保存的访问控制 FileSecurity 规则 DirectorySecurityUse this constructor to create an access control rule that you can persist using the FileSecurity or DirectorySecurity class. 访问控制规则定义用户帐户权限,以确定在运行 Microsoft Windows 的计算机上允许或禁止的操作。Access control rules define user account rights that determine which actions are allowed or disallowed on computers running Microsoft Windows.

适用于

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

使用以下内容初始化 FileSystemAccessRule 类的新实例:用户帐户的名称、指定与访问规则关联的操作的类型的值、确定如何继承权限的值、确定如何传播权限的值,以及指定是允许还是拒绝该操作的值。Initializes a new instance of the FileSystemAccessRule class using the name of a user account, a value that specifies the type of operation associated with the access rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies whether to allow or deny the operation.

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)

参数

identity
String

用户帐户的名称。The name of a user account.

fileSystemRights
FileSystemRights

FileSystemRights 值之一,该值指定与访问规则关联的操作的类型。One of the FileSystemRights values that specifies the type of operation associated with the access rule.

inheritanceFlags
InheritanceFlags

InheritanceFlags 值之一,该值指定访问掩码如何传播到子对象。One of the InheritanceFlags values that specifies how access masks are propagated to child objects.

propagationFlags
PropagationFlags

PropagationFlags 值之一,该值指定访问控制项 (ACE) 如何传播到子对象。One of the PropagationFlags values that specifies how Access Control Entries (ACEs) are propagated to child objects.

type
AccessControlType

AccessControlType 值之一,该值指定是允许还是拒绝该操作。One of the AccessControlType values that specifies whether to allow or deny the operation.

例外

identity 参数为 nullThe identity parameter is null.

一个错误枚举被传递给 type 参数。An incorrect enumeration was passed to the type parameter.

- 或 --or- 一个错误枚举被传递给 inheritanceFlags 参数。An incorrect enumeration was passed to the inheritanceFlags parameter.

- 或 --or- 一个错误枚举被传递给 propagationFlags 参数。An incorrect enumeration was passed to the propagationFlags parameter.

注解

使用此构造函数创建一个可以使用或类持久保存的访问控制 FileSecurity 规则 DirectorySecurityUse this constructor to create an access control rule that you can persist using the FileSecurity or DirectorySecurity class. 访问控制规则定义用户帐户权限,以确定在运行 Microsoft Windows 的计算机上允许或禁止的操作。Access control rules define user account rights that determine which actions are allowed or disallowed on computers running Microsoft Windows.

identity参数必须标识当前计算机或域上的有效帐户。The identity parameter must identify a valid account on the current computer or domain. 此字符串采用以下形式,其中 DOMAIN 是有效域或计算机名称的名称, account 是域或计算机上有效用户帐户的名称: DOMAIN\accountThe string takes the following form, where DOMAIN is the name of a valid domain or computer name and account is the name of a valid user account on a domain or computer: DOMAIN\account.

适用于