FileSystemRights 列挙型

定義

アクセス規則と監査規則の作成時に使用するアクセス権を定義します。

この列挙体は、メンバー値のビットごとの組み合わせをサポートしています。

public enum class FileSystemRights
[System.Flags]
public enum FileSystemRights
[System.Flags]
[System.Security.SecurityCritical]
public enum FileSystemRights
[<System.Flags>]
type FileSystemRights = 
[<System.Flags>]
[<System.Security.SecurityCritical>]
type FileSystemRights = 
Public Enum FileSystemRights
継承
FileSystemRights
属性

フィールド

AppendData 4

ファイルの末尾にデータを追加する権限を指定します。

ChangePermissions 262144

ファイルまたはフォルダーに関連付けられたセキュリティ規則と監査規則を変更する権限を指定します。

CreateDirectories 4

フォルダーを作成する権限を指定します。この権限には値が Synchronize 必要です。

CreateFiles 2

ファイルを作成する権限を指定します。 この権限には 値が必要です Synchronize

Delete 65536

フォルダーまたはファイルを削除する権限を指定します。

DeleteSubdirectoriesAndFiles 64

フォルダーおよびそのフォルダー内に格納されているファイルを削除する権限を指定します。

ExecuteFile 32

アプリケーション ファイルを実行する権限を指定します。

FullControl 2032127

フォルダーまたはファイルに対してフル コントロールを行い、アクセス制御と監査規則を変更する権限を指定します。 この値は、ファイルに対してどのような操作でも行うことができる権限を表します。この値は、この列挙体のすべての権限を組み合わせたものです。

ListDirectory 1

ディレクトリの内容を読み取る権限を指定します。

Modify 197055

読み取り、書き込み、フォルダーの内容の一覧表示、フォルダーとファイルの削除、およびアプリケーション ファイルの実行を行う権限を指定します。 この権限には、ReadAndExecute 権限、Write 権限、および Delete 権限が含まれます。

Read 131209

フォルダーまたはファイルを読み取り専用として開いたり、コピーしたりする権限を指定します。 この権限には、ReadData 権限、ReadExtendedAttributes 権限、ReadAttributes 権限、および ReadPermissions 権限が含まれます。

ReadAndExecute 131241

フォルダーまたはファイルを読み取り専用として開いたりコピーしたりする権限、およびアプリケーション ファイルを実行する権限を指定します。 この権限には、Read 権限および ExecuteFile 権限が含まれます。

ReadAttributes 128

フォルダーまたはファイルのファイル システム属性を開いたり、コピーしたりする権限を指定します。 たとえば、この値は、ファイルの作成日や変更日を表示する権限を指定します。 これには、データ、拡張ファイル システム属性、またはアクセス規則や監査規則を読み取る権限は含まれません。

ReadData 1

ファイルまたはフォルダーを開いたり、コピーしたりする権限を指定します。 これには、ファイル システム属性、拡張ファイル システム属性、またはアクセス規則や監査規則を読み取る権限は含まれません。

ReadExtendedAttributes 8

フォルダーまたはファイルの拡張ファイル システム属性を開いたり、コピーしたりする権限を指定します。 たとえば、この値は、作成者や内容に関する情報を表示する権限を指定します。 これには、データ、ファイル システム属性、またはアクセス規則や監査規則を読み取る権限は含まれません。

ReadPermissions 131072

フォルダーまたはファイルのアクセス規則や監査規則を開いたり、コピーしたりする権限を指定します。 これには、データ、ファイル システム属性、および拡張ファイル システム属性を読み取る権限は含まれません。

Synchronize 1048576

ファイル ハンドルが I/O 操作の完了に同期するまでアプリケーションが待機できるかどうかを指定します。 この値はアクセスを許可したときに自動的に設定され、アクセスを拒否したときには自動的に除外されます。

TakeOwnership 524288

フォルダーまたはファイルの所有者を変更する権限を指定します。 リソースの所有者は、そのリソースに対してフル アクセス権限を持ちます。

Traverse 32

フォルダーの内容を一覧表示し、そのフォルダーに格納されているアプリケーションを実行する権限を指定します。

Write 278

フォルダーおよびファイルを作成し、ファイルに対してデータの追加または削除を行う権限を指定します。 この権限には、WriteData 権限、AppendData 権限、WriteExtendedAttributes 権限、および WriteAttributes 権限が含まれます。

WriteAttributes 256

フォルダーまたはファイルのファイル システム属性を開いたり、フォルダーまたはファイルにファイル システム属性を書き込んだりする権限を指定します。 これには、データ、拡張属性、またはアクセス規則や監査規則を書き込む権限は含まれません。

WriteData 2

ファイルまたはフォルダーを開いたり、ファイルまたはフォルダーに書き込んだりする権限を指定します。 これには、ファイル システム属性、拡張ファイル システム属性、またはアクセス規則や監査規則を開いたり書き込んだりする権限は含まれません。

WriteExtendedAttributes 16

フォルダーまたはファイルの拡張ファイル システム属性を開いたり、フォルダーまたはファイルに拡張ファイル システム属性を書き込んだりする権限を指定します。 これには、データ、属性、またはアクセス規則や監査規則を書き込む権限は含まれません。

次の例では、 列挙を FileSystemRights 使用してアクセス規則を指定し、ファイルからアクセス規則を削除します。 この例を実行するには、有効なユーザーまたはグループ アカウントを指定する必要があります。

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

注釈

列挙体は FileSystemRights 、特定のユーザー アカウントに対して許可されるファイル システム アクションと、特定のユーザー アカウントに対して監査されるファイル システム アクションを指定します。

クラスを使用して FileSystemRights アクセス 規則を作成するとき、または クラスで FileSystemAccessRule 監査規則 FileSystemAuditRule を作成するときに、 列挙を使用します。

この列挙には、いくつかの詳細なシステム権限値と、これらの詳細な値の組み合わせであるいくつかの値が含まれています。 各コンポーネント値を個別に指定するよりも、、Read、、 WriteなどのFullControl組み合わせの値を使用する方が簡単です。

権限と CreateFiles 権限にはCreateDirectories、権利が必要ですSynchronize。 ファイルまたはディレクトリの作成時に値を Synchronize 明示的に設定しない場合は、自動的に設定されます。

適用対象