FileSecurity クラス

定義

ファイルのアクセス制御および監査セキュリティを表します。 このクラスは継承できません。

public ref class FileSecurity sealed : System::Security::AccessControl::FileSystemSecurity
public sealed class FileSecurity : System.Security.AccessControl.FileSystemSecurity
[System.Security.SecurityCritical]
public sealed class FileSecurity : System.Security.AccessControl.FileSystemSecurity
type FileSecurity = class
    inherit FileSystemSecurity
[<System.Security.SecurityCritical>]
type FileSecurity = class
    inherit FileSystemSecurity
Public NotInheritable Class FileSecurity
Inherits FileSystemSecurity
継承
属性

次のコード例では、 クラスを FileSecurity 使用して、ファイルにアクセス制御リスト (ACL) エントリを追加して削除します。 この例を実行するには、有効なユーザーまたはグループ アカウントを指定する必要があります。

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 、システム ファイルのアクセス権と、アクセス試行の監査方法を指定します。 このクラスは、一連の規則としてアクセス権と監査権限を表します。 各アクセス 規則は オブジェクトで FileSystemAccessRule 表され、各監査規則は オブジェクトによって FileSystemAuditRule 表されます。

クラスはFileSecurity、基になるMicrosoft Windows ファイル セキュリティ システムの抽象化です。 このシステムでは、各ファイルには、ファイルへのアクセスを制御する随意アクセス制御リスト (DACL) と、監査されるアクセス制御の試行を指定するシステム アクセス制御リスト (SACL) があります。 FileSystemAccessRuleクラスと FileSystemAuditRule クラスは、DAC と SACL を構成するアクセス制御エントリ (ACE) の抽象化です。

クラスでは FileSecurity 、DACL と SACL の詳細の多くが非表示になります。ACE の順序付けや NULL DACLS について心配する必要はありません。

クラスを FileSecurity 使用して、ファイルの DACL と SACL を表すアクセス規則を取得、追加、または変更します。

新しいアクセス規則または変更されたアクセス規則または監査規則をファイルに保持するには、 メソッドを使用します SetAccessControl 。 既存のファイルからアクセス規則または監査規則を取得するには、GetAccessControl メソッドを使用します。

コンストラクター

FileSecurity()

FileSecurity クラスの新しいインスタンスを初期化します。

FileSecurity(String, AccessControlSections)

FileSecurity 列挙体の値を指定して、指定したファイルの AccessControlSections クラスの新しいインスタンスを初期化します。

プロパティ

AccessRightType

FileSystemSecurity クラスでアクセス権を表すために使用する列挙体を取得します。

(継承元 FileSystemSecurity)
AccessRulesModified

この ObjectSecurity オブジェクトに関連するアクセス規則が変更されたかどうかを指定するブール値を取得または設定します。

(継承元 ObjectSecurity)
AccessRuleType

FileSystemSecurity クラスでアクセス規則を表すために使用する列挙体を取得します。

(継承元 FileSystemSecurity)
AreAccessRulesCanonical

この ObjectSecurity オブジェクトに関連するアクセス規則の順序が正規順序であるかどうかを指定するブール値を取得します。

(継承元 ObjectSecurity)
AreAccessRulesProtected

この ObjectSecurity オブジェクトに関連付けられている随意アクセス制御リスト (DACL) が保護されているかどうかを指定するブール値を取得します。

(継承元 ObjectSecurity)
AreAuditRulesCanonical

この ObjectSecurity オブジェクトに関連する監査規則の順序が正規順序であるかどうかを指定するブール値を取得します。

(継承元 ObjectSecurity)
AreAuditRulesProtected

この ObjectSecurity オブジェクトに関連付けられているシステム アクセス制御リスト (SACL) が保護されているかどうかを指定するブール値を取得します。

(継承元 ObjectSecurity)
AuditRulesModified

この ObjectSecurity オブジェクトに関連する監査規則が変更されたかどうかを指定するブール値を取得または設定します。

(継承元 ObjectSecurity)
AuditRuleType

FileSystemSecurity クラスで監査規則を表すために使用する型を取得します。

(継承元 FileSystemSecurity)
GroupModified

セキュリティ保護可能なオブジェクトと関連付けられているグループが変更されているかどうかを指定するブール値を取得または設定します。

(継承元 ObjectSecurity)
IsContainer

この ObjectSecurity オブジェクトがコンテナー オブジェクトかどうかを指定するブール値を取得します。

(継承元 ObjectSecurity)
IsDS

この ObjectSecurity オブジェクトがディレクトリ オブジェクトかどうかを指定するブール値を取得します。

(継承元 ObjectSecurity)
OwnerModified

セキュリティ保護可能なオブジェクトの所有者が変更されているかどうかを指定するブール値を取得または設定します。

(継承元 ObjectSecurity)
SecurityDescriptor

このインスタンスのセキュリティ記述子を取得します。

(継承元 ObjectSecurity)

メソッド

AccessRuleFactory(IdentityReference, Int32, Boolean, InheritanceFlags, PropagationFlags, AccessControlType)

アクセス権、アクセス制御、およびフラグを指定して、指定したユーザーの新しいアクセス制御規則を表す FileSystemAccessRule クラスの新しいインスタンスを初期化します。

(継承元 FileSystemSecurity)
AddAccessRule(AccessRule)

指定したアクセス規則を、この CommonObjectSecurity オブジェクトに関連付けられた随意アクセス制御リスト (DACL: Discretionary Access Control List) に追加します。

(継承元 CommonObjectSecurity)
AddAccessRule(FileSystemAccessRule)

アクセス制御リスト (ACL) の指定したアクセス許可を現在のファイルまたはディレクトリに追加します。

(継承元 FileSystemSecurity)
AddAuditRule(AuditRule)

指定した監査規則を、この CommonObjectSecurity オブジェクトに関連付けられたシステム アクセス制御リスト (SACL: System Access Control List) に追加します。

(継承元 CommonObjectSecurity)
AddAuditRule(FileSystemAuditRule)

指定した監査規則を現在のファイルまたはディレクトリに追加します。

(継承元 FileSystemSecurity)
AuditRuleFactory(IdentityReference, Int32, Boolean, InheritanceFlags, PropagationFlags, AuditFlags)

指定したユーザーの指定した監査規則を表す FileSystemAuditRule クラスの新しいインスタンスを初期化します。

(継承元 FileSystemSecurity)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetAccessRules(Boolean, Boolean, Type)

指定したセキュリティ識別子に関連付けられたアクセス規則のコレクションを取得します。

(継承元 CommonObjectSecurity)
GetAuditRules(Boolean, Boolean, Type)

指定したセキュリティ識別子に関連付けられた監査規則のコレクションを取得します。

(継承元 CommonObjectSecurity)
GetGroup(Type)

指定された所有者に関連付けられているプライマリ グループを取得します。

(継承元 ObjectSecurity)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetOwner(Type)

指定されたプライマリ グループに関連付けられている所有者を取得します。

(継承元 ObjectSecurity)
GetSecurityDescriptorBinaryForm()

この ObjectSecurity オブジェクトに関するセキュリティ記述子の情報を表すバイト値の配列を返します。

(継承元 ObjectSecurity)
GetSecurityDescriptorSddlForm(AccessControlSections)

ObjectSecurity オブジェクトに関連付けられているセキュリティ記述子の指定したセクションにあるセキュリティ記述子定義言語 (SDDL) 表現を返します。

(継承元 ObjectSecurity)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ModifyAccess(AccessControlModification, AccessRule, Boolean)

この CommonObjectSecurity オブジェクトに関連付けられている随意アクセス制御リスト (DACL) への指定された変更を適用します。

(継承元 CommonObjectSecurity)
ModifyAccessRule(AccessControlModification, AccessRule, Boolean)

この ObjectSecurity オブジェクトに関連付けられている随意アクセス制御リスト (DACL) への指定された変更を適用します。

(継承元 ObjectSecurity)
ModifyAudit(AccessControlModification, AuditRule, Boolean)

指定された変更を、この CommonObjectSecurity オブジェクトに関連付けられているシステム アクセス制御リスト (SACL) に適用します。

(継承元 CommonObjectSecurity)
ModifyAuditRule(AccessControlModification, AuditRule, Boolean)

指定された変更を、この ObjectSecurity オブジェクトに関連付けられているシステム アクセス制御リスト (SACL) に適用します。

(継承元 ObjectSecurity)
Persist(Boolean, String, AccessControlSections)

この ObjectSecurity オブジェクトに関連付けられたセキュリティ記述子の指定されたセクションを、永続ストレージに保存します。 コンストラクターと persist メソッドに渡される includeSections パラメーターの値を同一にすることをお勧めします。

(継承元 ObjectSecurity)
Persist(SafeHandle, AccessControlSections)

この NativeObjectSecurity オブジェクトに関連付けられたセキュリティ記述子の指定されたセクションを、永続ストレージに保存します。 コンストラクターと persist メソッドに渡される includeSections パラメーターの値を同一にすることをお勧めします。

(継承元 NativeObjectSecurity)
Persist(SafeHandle, AccessControlSections, Object)

この NativeObjectSecurity オブジェクトに関連付けられたセキュリティ記述子の指定されたセクションを、永続ストレージに保存します。 コンストラクターと persist メソッドに渡される includeSections パラメーターの値を同一にすることをお勧めします。

(継承元 NativeObjectSecurity)
Persist(String, AccessControlSections)

この NativeObjectSecurity オブジェクトに関連付けられたセキュリティ記述子の指定されたセクションを、永続ストレージに保存します。 コンストラクターと persist メソッドに渡される includeSections パラメーターの値を同一にすることをお勧めします。

(継承元 NativeObjectSecurity)
Persist(String, AccessControlSections, Object)

この NativeObjectSecurity オブジェクトに関連付けられたセキュリティ記述子の指定されたセクションを、永続ストレージに保存します。 コンストラクターと persist メソッドに渡される includeSections パラメーターの値を同一にすることをお勧めします。

(継承元 NativeObjectSecurity)
PurgeAccessRules(IdentityReference)

指定した IdentityReference と関連付けられているすべてのアクセス規則をすべて削除します。

(継承元 ObjectSecurity)
PurgeAuditRules(IdentityReference)

指定した IdentityReference と関連付けられている監査規則をすべて削除します。

(継承元 ObjectSecurity)
ReadLock()

読み取りアクセス用のこの ObjectSecurity オブジェクトをロックします。

(継承元 ObjectSecurity)
ReadUnlock()

読み取りアクセス用のこの ObjectSecurity オブジェクトをロック解除します。

(継承元 ObjectSecurity)
RemoveAccessRule(AccessRule)

指定したアクセス規則と同じセキュリティ識別子とアクセス マスクを含むアクセス規則を、この CommonObjectSecurity オブジェクトに関連付けられた随意アクセス制御リスト (DACL: Discretionary Access Control List) から削除します。

(継承元 CommonObjectSecurity)
RemoveAccessRule(FileSystemAccessRule)

現在のファイルまたはディレクトリから、アクセス制御リスト (ACL) の一致するすべての許可するアクセス許可、または拒否するアクセス許可を削除します。

(継承元 FileSystemSecurity)
RemoveAccessRuleAll(AccessRule)

指定したアクセス規則と同じセキュリティ識別子を含むすべてのアクセス規則を、この CommonObjectSecurity オブジェクトに関連付けられた随意アクセス制御リスト (DACL: Discretionary Access Control List) から削除します。

(継承元 CommonObjectSecurity)
RemoveAccessRuleAll(FileSystemAccessRule)

現在のファイルまたはディレクトリから、指定したユーザーのアクセス制御リスト (ACL) のすべてのアクセス許可を削除します。

(継承元 FileSystemSecurity)
RemoveAccessRuleSpecific(AccessRule)

指定したアクセス規則と完全に一致するすべてのアクセス規則を、この CommonObjectSecurity オブジェクトに関連付けられた随意アクセス制御リスト (DACL: Discretionary Access Control List) から削除します。

(継承元 CommonObjectSecurity)
RemoveAccessRuleSpecific(FileSystemAccessRule)

現在のファイルまたはディレクトリから、アクセス制御リスト (ACL) の一致する単一の許可するアクセス許可、または拒否するアクセス許可を削除します。

(継承元 FileSystemSecurity)
RemoveAuditRule(AuditRule)

指定した監査規則と同じセキュリティ識別子とアクセス マスクを含む監査規則を、この CommonObjectSecurity オブジェクトに関連付けられたシステム アクセス制御リスト (SACL: System Access Control List) から削除します。

(継承元 CommonObjectSecurity)
RemoveAuditRule(FileSystemAuditRule)

現在のファイルまたはディレクトリから、一致するすべての許可する監査規則または拒否する監査規則を削除します。

(継承元 FileSystemSecurity)
RemoveAuditRuleAll(AuditRule)

指定した監査規則と同じセキュリティ識別子を含むすべての監査規則を、この CommonObjectSecurity オブジェクトに関連付けられたシステム アクセス制御リスト (SACL: System Access Control List) から削除します。

(継承元 CommonObjectSecurity)
RemoveAuditRuleAll(FileSystemAuditRule)

現在のファイルまたはディレクトリから、指定したユーザーのすべての監査規則を削除します。

(継承元 FileSystemSecurity)
RemoveAuditRuleSpecific(AuditRule)

指定した監査規則と完全に一致するすべての監査規則を、この CommonObjectSecurity オブジェクトに関連付けられたシステム アクセス制御リスト (SACL: System Access Control List) から削除します。

(継承元 CommonObjectSecurity)
RemoveAuditRuleSpecific(FileSystemAuditRule)

現在のファイルまたはディレクトリから、一致する単一の許可する監査規則または拒否する監査規則を削除します。

(継承元 FileSystemSecurity)
ResetAccessRule(AccessRule)

この CommonObjectSecurity オブジェクトに関連付けられた随意アクセス制御リスト (DACL: Discretionary Access Control List) 内のすべてのアクセス規則を削除し、指定したアクセス規則を追加します。

(継承元 CommonObjectSecurity)
ResetAccessRule(FileSystemAccessRule)

アクセス制御リスト (ACL) の指定したアクセス許可を現在のファイルまたはディレクトリに追加し、ACL の一致するすべてのアクセス許可を削除します。

(継承元 FileSystemSecurity)
SetAccessRule(AccessRule)

指定したアクセス規則と同じセキュリティ識別子と修飾子を含むすべてのアクセス規則を、この CommonObjectSecurity オブジェクトに関連付けられた随意アクセス制御リスト (DACL: Discretionary Access Control List) から削除し、指定したアクセス規則を追加します。

(継承元 CommonObjectSecurity)
SetAccessRule(FileSystemAccessRule)

現在のファイルまたはディレクトリに、アクセス制御リスト (ACL) の指定したアクセス許可を設定します。

(継承元 FileSystemSecurity)
SetAccessRuleProtection(Boolean, Boolean)

この ObjectSecurity オブジェクトに関連付けられたアクセス規則の保護を設定または削除します。 保護されたアクセス規則を親オブジェクトが継承によって変更することはできません。

(継承元 ObjectSecurity)
SetAuditRule(AuditRule)

指定した監査規則と同じセキュリティ識別子と修飾子を含むすべての監査規則を、この CommonObjectSecurity オブジェクトに関連付けられたシステム アクセス制御リスト (SACL: System Access Control List) から削除し、指定した監査規則を追加します。

(継承元 CommonObjectSecurity)
SetAuditRule(FileSystemAuditRule)

現在のファイルまたはディレクトリに指定した監査規則を設定します。

(継承元 FileSystemSecurity)
SetAuditRuleProtection(Boolean, Boolean)

この ObjectSecurity オブジェクトに関連付けられた監査規則の保護を設定または削除します。 保護された監査規則は、親オブジェクトによる継承によって変更できません。

(継承元 ObjectSecurity)
SetGroup(IdentityReference)

この ObjectSecurity オブジェクトに関連付けられているセキュリティ記述子のプライマリ グループを設定します。

(継承元 ObjectSecurity)
SetOwner(IdentityReference)

このObjectSecurity オブジェクトに関連付けられているセキュリティ記述子の所有者を設定します。

(継承元 ObjectSecurity)
SetSecurityDescriptorBinaryForm(Byte[])

バイト値の指定された配列から、この ObjectSecurity オブジェクトに関するセキュリティ記述子を設定します。

(継承元 ObjectSecurity)
SetSecurityDescriptorBinaryForm(Byte[], AccessControlSections)

バイト値の指定された配列から、この ObjectSecurity オブジェクトに関するセキュリティ記述子の指定されたセクションを設定します。

(継承元 ObjectSecurity)
SetSecurityDescriptorSddlForm(String)

指定したセキュリティ記述子定義言語 (SDDL) 文字列から、ObjectSecurity オブジェクトのセキュリティ記述子を設定します。

(継承元 ObjectSecurity)
SetSecurityDescriptorSddlForm(String, AccessControlSections)

指定したセキュリティ記述子定義言語 (SDDL) 文字列から、ObjectSecurity オブジェクトのセキュリティ記述子の指定したセクションを設定します。

(継承元 ObjectSecurity)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
WriteLock()

書き込みアクセス用のこの ObjectSecurity オブジェクトをロックします。

(継承元 ObjectSecurity)
WriteUnlock()

書き込みアクセス用にこの ObjectSecurity オブジェクトのロックを解除します。

(継承元 ObjectSecurity)

適用対象