请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
 FileSystemRights 枚举

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
FileSystemRights 枚举

注意:此枚举在 .NET Framework 2.0 版中是新增的。

定义要在创建访问和审核规则时使用的访问权限。

此枚举有一个 FlagsAttribute 属性,允许其成员值按位组合。

命名空间:System.Security.AccessControl
程序集:mscorlib(在 mscorlib.dll 中)

Visual Basic(声明)
<FlagsAttribute> _
Public Enumeration FileSystemRights
Visual Basic(用法)
Dim instance As FileSystemRights
C#
[FlagsAttribute] 
public enum FileSystemRights
C++
[FlagsAttribute] 
public enum class FileSystemRights
J#
/** @attribute FlagsAttribute() */ 
public enum FileSystemRights
JScript
FlagsAttribute 
public enum FileSystemRights
 成员名称说明
AppendData指定将数据追加到文件末尾的权限。 
ChangePermissions指定更改与文件或文件夹关联的安全和审核规则的权限。 
CreateDirectories指定创建文件夹的权限。  

此权限需要 Synchronize 值。请注意,如果在创建文件或文件夹时未显式设置 Synchronize 值,则会自动为您设置 Synchronize 值。

CreateFiles指定创建文件的权限。  

此权限需要 Synchronize 值。请注意,如果在创建文件或文件夹时未显式设置 Synchronize 值,则会自动为您设置 Synchronize 值。

Delete指定删除文件夹或文件的权限。  
DeleteSubdirectoriesAndFiles指定删除文件夹和该文件夹中包含的所有文件的权限。 
ExecuteFile指定运行应用程序文件的权限。 
FullControl指定对文件夹或文件进行完全控制以及修改访问控制和审核规则的权限。此值表示对文件进行任何操作的权限,并且是此枚举中的所有权限的组合。 
ListDirectory指定读取目录内容的权限。 
Modify指定读、写、列出文件夹内容、删除文件夹和文件以及运行应用程序文件的权限。此权限包括 ReadAndExecute 权限、Write 权限和 Delete 权限。 
Read指定以只读方式打开和复制文件夹或文件的权限。此权限包括 ReadData 权限、ReadExtendedAttributes 权限、ReadAttributes 权限和 ReadPermissions 权限。 
ReadAndExecute指定以只读方式打开和复制文件夹或文件以及运行应用程序文件的权限。此权限包括 Read 权限和 ExecuteFile 权限。 
ReadAttributes指定从文件夹或文件打开和复制文件系统属性的权限。例如,此值指定查看文件创建日期或修改日期的权限。这不包括读取数据、扩展文件系统属性或访问和审核规则的权限。 
ReadData指定打开和复制文件或文件夹的权限。这不包括读取文件系统属性、扩展文件系统属性或访问和审核规则的权限。 
ReadExtendedAttributes指定从文件夹或文件打开和复制扩展文件系统属性的权限。例如,此值指定查看作者和内容信息的权限。这不包括读取数据、文件系统属性或访问和审核规则的权限。 
ReadPermissions指定从文件夹或文件打开和复制访问和审核规则的权限。这不包括读取数据、文件系统属性或扩展文件系统属性的权限。  
Synchronize指定应用程序是否能够等待文件句柄,以便与 I/O 操作的完成保持同步。 

Synchronize 值在允许访问时自动被设置,而在拒绝访问时自动被排除。

创建文件或文件夹的权限需要此值。请注意,如果在创建文件时未显式设置此值,则会自动为您设置此值。

TakeOwnership指定更改文件夹或文件的所有者的权限。请注意:资源的所有者对该资源拥有完全权限。 
Traverse指定列出文件夹的内容以及运行该文件夹中所包含的应用程序的权限。 
Write指定创建文件夹和文件以及向文件添加数据或从文件移除数据的权限。此权限包括 WriteData 权限、AppendData 权限、WriteExtendedAttributes 权限和 WriteAttributes 权限。  
WriteAttributes指定打开文件系统属性以及将文件系统属性写入文件夹或文件的权限。这不包括写入数据、扩展属性以及写入访问和审核规则的功能。 
WriteData指定打开和写入文件或文件夹的权限。这不包括打开和写入文件系统属性、扩展文件系统属性或访问和审核规则的权限。 
WriteExtendedAttributes指定打开文件夹或文件的扩展文件系统属性以及将扩展文件系统属性写入文件夹或文件的权限。这不包括写入数据、属性或访问和审核规则的功能。 

FileSystemRights 枚举指定对于某个特定用户帐户允许哪些文件系统操作,以及对于某个特定用户帐户审核哪些文件系统操作。

在使用 FileSystemAccessRule 类创建访问规则或在使用 FileSystemAuditRule 类创建审核规则时使用 FileSystemRights 枚举。

此枚举包含几个粒度级的系统权限值和这些粒度值的几个组合值。与分别指定每个组件值相比,使用 FullControlReadWrite 等组合值更加容易。

下面的代码示例使用 FileSystemRights 枚举指定一条访问规则,然后从文件移除该访问规则。您必须提供有效的用户或组帐户才能运行此示例。

Visual Basic
Imports System
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)

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

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

    End Sub
End Module
C#
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);

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

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

        }
    }
}
C++
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 to 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);
    }
}

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

.NET Framework

受以下版本支持:2.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker