FileSystemAuditRule クラス

定義

ファイルまたはディレクトリの監査規則を定義するアクセス制御エントリ (ACE: Access Control Entry) の抽象化を表します。 このクラスは継承できません。

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

次のコード例では、 クラスを FileSystemAuditRule 使用して、ファイルに対する監査規則の追加と削除を行います。 この例を実行するには、有効なユーザーまたはグループ アカウントを指定する必要があります。

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.
                AddFileAuditRule(FileName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AuditFlags.Failure);

                Console.WriteLine("Removing access control entry from " + FileName);

                // Remove the access control entry from the file.
                RemoveFileAuditRule(FileName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AuditFlags.Failure);

                Console.WriteLine("Done.");
            }
            catch (IOException e)
            {
                Console.WriteLine("Unable to open the file: " + e.Message);
            }
            catch (PrivilegeNotHeldException e)
            {
                Console.WriteLine("The current account does not have the correct privileges: " + e.Message);
            }

            Console.ReadLine();
        }

        // Adds an ACL entry on the specified file for the specified account.
        public static void AddFileAuditRule(string FileName, string Account, FileSystemRights Rights, AuditFlags AuditRule)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(FileName);

            // Add the FileSystemAuditRule to the security settings.
            fSecurity.AddAuditRule(new FileSystemAuditRule(Account,
                                                            Rights,
                                                            AuditRule));

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

        // Removes an ACL entry on the specified file for the specified account.
        public static void RemoveFileAuditRule(string FileName, string Account, FileSystemRights Rights, AuditFlags AuditRule)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(FileName);

            // Add the FileSystemAuditRule to the security settings.
            fSecurity.RemoveAuditRule(new FileSystemAuditRule(Account,
                                                            Rights,
                                                            AuditRule));

            // 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.
            AddFileAuditRule(FileName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AuditFlags.Failure)

            Console.WriteLine("Removing access control entry from " + FileName)

            ' Remove the access control entry from the file.
            RemoveFileAuditRule(FileName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AuditFlags.Failure)

            Console.WriteLine("Done.")
        Catch e As IOException
            Console.WriteLine("Unable to open the file: " & e.Message)
        Catch e As PrivilegeNotHeldException
            Console.WriteLine("The current account does not have the correct privileges: " & e.Message)
        End Try

        Console.ReadLine()

    End Sub


    ' Adds an ACL entry on the specified file for the specified account.
    Sub AddFileAuditRule(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal AuditRule As AuditFlags)


        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(FileName)

        ' Add the FileSystemAuditRule to the security settings. 
        fSecurity.AddAuditRule(New FileSystemAuditRule(Account, Rights, AuditRule))

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

    End Sub


    ' Removes an ACL entry on the specified file for the specified account.
    Sub RemoveFileAuditRule(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal AuditRule As AuditFlags)

        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(FileName)

        ' Add the FileSystemAuditRule to the security settings. 
        fSecurity.RemoveAuditRule(New FileSystemAuditRule(Account, Rights, AuditRule))

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

    End Sub
End Module

注釈

クラスは FileSystemAuditRule 、ユーザー アカウント、提供するアクセスの種類 (読み取り、書き込みなど)、および監査を実行するかどうかを指定する基になるアクセス制御エントリ (ACE) の抽象化を表します。 このクラスでは、監査規則の継承方法とオブジェクトへの伝達方法を指定することもできます。

Windows NT 以降でファイルとディレクトリの監査を許可するには、コンピューターで監査アクセス セキュリティ ポリシーを有効にする必要があります。 既定では、このポリシーは [監査なし] に設定されています。

監査アクセス セキュリティ ポリシーを有効にするには、次の手順を実行します。

  1. [管理ツール] フォルダーにある [ローカル セキュリティ設定] Microsoft管理コンソール (MMC) スナップインを開きます。

  2. [ローカル ポリシー] フォルダーを展開し、[監査ポリシー] フォルダーを左クリックします。

  3. MMC スナップインの右側のウィンドウで [ Audit object access ]\(オブジェクト アクセスの監査\) エントリをダブルクリックするか、右クリックして [プロパティ] を選択して [ Audit object access properties]\(オブジェクト アクセスプロパティの監査\ ) ダイアログ ボックスを表示します。

  4. [成功] または [失敗] チェック ボックスをオンにして、成功または失敗をログに記録します。

ユーザー アカウントの監査規則には、同じユーザー アカウントに対応するアクセス規則が必要であることに注意してください。

クラスを FileSystemAuditRule 使用して、新しい監査規則を作成します。 この規則は、 クラスまたは DirectorySecurity クラスをFileSecurity使用して保持できます。

コンストラクター

FileSystemAuditRule(IdentityReference, FileSystemRights, AuditFlags)

ユーザー アカウントへの参照、監査規則に関連付けられた操作の種類を指定する値、およびいつ監査を実行するのかを指定する値を使用して、FileSystemAuditRule クラスの新しいインスタンスを初期化します。

FileSystemAuditRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AuditFlags)

ユーザー アカウントへの参照の名前、監査規則に関連付けられた操作の種類を指定する値、権限の継承方法を決定する値、権限の反映方法を決定する値、およびいつ監査を実行するのかを指定する値を使用して、FileSystemAuditRule クラスの新しいインスタンスを初期化します。

FileSystemAuditRule(String, FileSystemRights, AuditFlags)

ユーザー アカウント名、監査規則に関連付けられた操作の種類を指定する値、およびいつ監査を実行するのかを指定する値を使用して、FileSystemAuditRule クラスの新しいインスタンスを初期化します。

FileSystemAuditRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AuditFlags)

ユーザー アカウント名、監査規則に関連付けられた操作の種類を指定する値、権限の継承方法を決定する値、権限の反映方法を決定する値、およびいつ監査を実行するのかを指定する値を使用して、FileSystemAuditRule クラスの新しいインスタンスを初期化します。

プロパティ

AccessMask

この規則のアクセス マスクを取得します。

(継承元 AuthorizationRule)
AuditFlags

この監査規則の監査フラグを取得します。

(継承元 AuditRule)
FileSystemRights

現在の FileSystemRights オブジェクトに関連付けられている FileSystemAuditRule フラグを取得します。

IdentityReference

この規則を適用する IdentityReference を取得します。

(継承元 AuthorizationRule)
InheritanceFlags

この規則を子オブジェクトが継承する方法を決定するフラグの値を取得します。

(継承元 AuthorizationRule)
IsInherited

この規則を明示的に設定するか、または親コンテナー オブジェクトから継承するかを指定する値を取得します。

(継承元 AuthorizationRule)
PropagationFlags

反映フラグの値を取得します。このフラグから、この規則を子オブジェクトに反映させる方法を判断します。 このプロパティは、InheritanceFlags 列挙体の値が None でない場合にのみ重要です。

(継承元 AuthorizationRule)

メソッド

Equals(Object)

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

(継承元 Object)
GetHashCode()

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

(継承元 Object)
GetType()

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

(継承元 Object)
MemberwiseClone()

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

(継承元 Object)
ToString()

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

(継承元 Object)

適用対象