FileSystemAuditRule Constructors

Definition

初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class.

Overloads

FileSystemAuditRule(IdentityReference, FileSystemRights, AuditFlags)

利用使用者帳戶的參考、指定與稽核規則關聯之作業類型的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class using a reference to a user account, a value that specifies the type of operation associated with the audit rule, and a value that specifies when to perform auditing.

FileSystemAuditRule(String, FileSystemRights, AuditFlags)

利用使用者帳戶名稱、指定與稽核規則關聯之作業類型的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class using a user account name, a value that specifies the type of operation associated with the audit rule, and a value that specifies when to perform auditing.

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

利用使用者帳戶的參考名稱、指定與稽核規則關聯之作業類型的值、決定如何繼承權限的值、決定如何散佈權限的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class using the name of a reference to a user account, a value that specifies the type of operation associated with the audit rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies when to perform auditing.

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

利用使用者帳戶名稱、指定與稽核規則關聯之作業類型的值、決定如何繼承權限的值、決定如何散佈權限的值,以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class using the name of a user account, a value that specifies the type of operation associated with the audit rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies when to perform auditing.

FileSystemAuditRule(IdentityReference, FileSystemRights, AuditFlags)

利用使用者帳戶的參考、指定與稽核規則關聯之作業類型的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class using a reference to a user account, a value that specifies the type of operation associated with the audit rule, and a value that specifies when to perform auditing.

public:
 FileSystemAuditRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AuditFlags flags);
public FileSystemAuditRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AuditFlags flags);
new System.Security.AccessControl.FileSystemAuditRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AuditFlags -> System.Security.AccessControl.FileSystemAuditRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, flags As AuditFlags)

Parameters

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 audit rule.

flags
AuditFlags

其中一個 AuditFlags 值,可指定何時要執行稽核。One of the AuditFlags values that specifies when to perform auditing.

Exceptions

identity 參數不是 IdentityReference 物件。The identity parameter is not an IdentityReference object.

identity 參數是 nullThe identity parameter is null.

不正確的列舉型別已傳遞至 flags 參數。An incorrect enumeration was passed to the flags parameter.

-或--or- None 值已傳遞至 flags 參數。The None value was passed to the flags parameter.

Remarks

使用此函式來建立可使用 FileSecurityDirectorySecurity 類別保存的審核規則。Use this constructor to create an audit rule that you can persist using the FileSecurity or DirectorySecurity class. Audit 規則會決定如何記錄在系統物件(例如檔案和資料夾)上執行的動作。Audit rules determine when and how actions performed on system objects, such as files and folders, are logged.

FileSystemAuditRule(String, FileSystemRights, AuditFlags)

利用使用者帳戶名稱、指定與稽核規則關聯之作業類型的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class using a user account name, a value that specifies the type of operation associated with the audit rule, and a value that specifies when to perform auditing.

public:
 FileSystemAuditRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AuditFlags flags);
public FileSystemAuditRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AuditFlags flags);
new System.Security.AccessControl.FileSystemAuditRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AuditFlags -> System.Security.AccessControl.FileSystemAuditRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, flags As AuditFlags)

Parameters

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 audit rule.

flags
AuditFlags

其中一個 AuditFlags 值,可指定何時要執行稽核。One of the AuditFlags values that specifies when to perform auditing.

Exceptions

不正確的列舉型別已傳遞至 flags 參數。An incorrect enumeration was passed to the flags parameter.

-或--or- None 值已傳遞至 flags 參數。The None value was passed to the flags parameter.

Examples

下列程式碼範例會使用 FileSystemAuditRule 類別,在檔案中新增和移除 audit 規則。The following code example uses the FileSystemAuditRule class to add and then remove an audit rule from a file. 您必須提供有效的使用者或群組帳戶,才能執行這個範例。You must supply a valid user or group account to run this example.

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

Remarks

使用此函式來建立可使用 FileSecurityDirectorySecurity 類別保存的審核規則。Use this constructor to create an audit rule that you can persist using the FileSecurity or DirectorySecurity class. Audit 規則會決定如何記錄在系統物件(例如檔案和資料夾)上執行的動作。Audit rules determine when and how actions performed on system objects, such as files and folders, are logged.

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.

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

利用使用者帳戶的參考名稱、指定與稽核規則關聯之作業類型的值、決定如何繼承權限的值、決定如何散佈權限的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class using the name of a reference to a user account, a value that specifies the type of operation associated with the audit rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies when to perform auditing.

public:
 FileSystemAuditRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AuditFlags flags);
public FileSystemAuditRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AuditFlags flags);
new System.Security.AccessControl.FileSystemAuditRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AuditFlags -> System.Security.AccessControl.FileSystemAuditRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, flags As AuditFlags)

Parameters

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 audit 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.

flags
AuditFlags

其中一個 AuditFlags 值,可指定何時要執行稽核。One of the AuditFlags values that specifies when to perform auditing.

Exceptions

identity 參數不是 IdentityReference 物件。The identity parameter is not an IdentityReference object.

identity 參數是 nullThe identity parameter is null.

不正確的列舉型別已傳遞至 flags 參數。An incorrect enumeration was passed to the flags parameter.

-或--or- None 值已傳遞至 flags 參數。The None value was passed to the flags parameter.

Remarks

使用此函式來建立可使用 FileSecurityDirectorySecurity 類別保存的審核規則。Use this constructor to create an audit rule that you can persist using the FileSecurity or DirectorySecurity class. Audit 規則會決定如何記錄在系統物件(例如檔案和資料夾)上執行的動作。Audit rules determine when and how actions performed on system objects, such as files and folders, are logged.

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

利用使用者帳戶名稱、指定與稽核規則關聯之作業類型的值、決定如何繼承權限的值、決定如何散佈權限的值,以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。Initializes a new instance of the FileSystemAuditRule class using the name of a user account, a value that specifies the type of operation associated with the audit rule, a value that determines how rights are inherited, a value that determines how rights are propagated, and a value that specifies when to perform auditing.

public:
 FileSystemAuditRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AuditFlags flags);
public FileSystemAuditRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AuditFlags flags);
new System.Security.AccessControl.FileSystemAuditRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AuditFlags -> System.Security.AccessControl.FileSystemAuditRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, flags As AuditFlags)

Parameters

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 audit 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.

flags
AuditFlags

其中一個 AuditFlags 值,可指定何時要執行稽核。One of the AuditFlags values that specifies when to perform auditing.

Remarks

使用此函式來建立可使用 FileSecurityDirectorySecurity 類別保存的審核規則。Use this constructor to create an audit rule that you can persist using the FileSecurity or DirectorySecurity class. Audit 規則會決定如何記錄在系統物件(例如檔案和資料夾)上執行的動作。Audit rules determine when and how actions performed on system objects, such as files and folders, are logged.

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.

Applies to