FileSystemAuditRule 建構函式

定義

初始化 FileSystemAuditRule 類別的新執行個體。

多載

FileSystemAuditRule(IdentityReference, FileSystemRights, AuditFlags)

利用使用者帳戶的參考、指定與稽核規則關聯之作業類型的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。

FileSystemAuditRule(String, FileSystemRights, AuditFlags)

利用使用者帳戶名稱、指定與稽核規則關聯之作業類型的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。

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

利用使用者帳戶的參考名稱、指定與稽核規則關聯之作業類型的值、決定如何繼承權限的值、決定如何散佈權限的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。

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

利用使用者帳戶名稱、指定與稽核規則關聯之作業類型的值、決定如何繼承權限的值、決定如何散佈權限的值,以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。

FileSystemAuditRule(IdentityReference, FileSystemRights, AuditFlags)

利用使用者帳戶的參考、指定與稽核規則關聯之作業類型的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。

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)

參數

identity
IdentityReference

IdentityReference 物件,封裝使用者帳戶的參考。

fileSystemRights
FileSystemRights

其中一個 FileSystemRights 值,可指定與稽核規則有關聯的作業類型。

flags
AuditFlags

其中一個 AuditFlags 值,可指定何時要執行稽核。

例外狀況

identity 參數不是 IdentityReference 物件。

identity 參數為 null

不正確的列舉型別已傳遞至 flags 參數。

-或-

None 值已傳遞至 flags 參數。

備註

使用此建構函式來建立您可以使用 或 DirectorySecurity 類別保存的 FileSecurity 稽核規則。 稽核規則會決定記錄系統物件上執行動作的時機和方式,例如檔案和資料夾。

適用於

FileSystemAuditRule(String, FileSystemRights, AuditFlags)

利用使用者帳戶名稱、指定與稽核規則關聯之作業類型的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。

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)

參數

identity
String

使用者帳戶的名稱。

fileSystemRights
FileSystemRights

其中一個 FileSystemRights 值,可指定與稽核規則有關聯的作業類型。

flags
AuditFlags

其中一個 AuditFlags 值,可指定何時要執行稽核。

例外狀況

不正確的列舉型別已傳遞至 flags 參數。

-或-

None 值已傳遞至 flags 參數。

範例

下列程式碼範例會 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

備註

使用此建構函式來建立您可以使用 或 DirectorySecurity 類別保存的 FileSecurity 稽核規則。 稽核規則會決定記錄系統物件上執行動作的時機和方式,例如檔案和資料夾。

參數 identity 必須識別目前電腦或網域的有效帳戶。 字串採用下列形式,其中 DOMAIN 是有效網域或電腦名稱稱的名稱,而且 account 是網域或電腦上的有效使用者帳戶名稱: DOMAIN\account

適用於

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

利用使用者帳戶的參考名稱、指定與稽核規則關聯之作業類型的值、決定如何繼承權限的值、決定如何散佈權限的值以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。

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)

參數

identity
IdentityReference

IdentityReference 物件,封裝使用者帳戶的參考。

fileSystemRights
FileSystemRights

其中一個 FileSystemRights 值,可指定與稽核規則有關聯的作業類型。

inheritanceFlags
InheritanceFlags

其中一個 InheritanceFlags 值,可指定存取遮罩要如何散佈到子物件。

propagationFlags
PropagationFlags

其中一個 PropagationFlags 值,可指定存取控制項目 (ACE) 要如何散佈到子物件。

flags
AuditFlags

其中一個 AuditFlags 值,可指定何時要執行稽核。

例外狀況

identity 參數不是 IdentityReference 物件。

identity 參數為 null

不正確的列舉型別已傳遞至 flags 參數。

-或-

None 值已傳遞至 flags 參數。

備註

使用此建構函式來建立您可以使用 或 DirectorySecurity 類別保存的 FileSecurity 稽核規則。 稽核規則會決定記錄系統物件上執行動作的時機和方式,例如檔案和資料夾。

適用於

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

利用使用者帳戶名稱、指定與稽核規則關聯之作業類型的值、決定如何繼承權限的值、決定如何散佈權限的值,以及指定何時執行稽核的值,來初始化 FileSystemAuditRule 類別的新執行個體。

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)

參數

identity
String

使用者帳戶的名稱。

fileSystemRights
FileSystemRights

其中一個 FileSystemRights 值,可指定與稽核規則有關聯的作業類型。

inheritanceFlags
InheritanceFlags

其中一個 InheritanceFlags 值,可指定存取遮罩要如何散佈到子物件。

propagationFlags
PropagationFlags

其中一個 PropagationFlags 值,可指定存取控制項目 (ACE) 要如何散佈到子物件。

flags
AuditFlags

其中一個 AuditFlags 值,可指定何時要執行稽核。

備註

使用此建構函式來建立您可以使用 或 DirectorySecurity 類別保存的 FileSecurity 稽核規則。 稽核規則會決定記錄系統物件上執行動作的時機和方式,例如檔案和資料夾。

參數 identity 必須識別目前電腦或網域的有效帳戶。 字串採用下列形式,其中 DOMAIN 是有效網域或電腦名稱稱的名稱,而且 account 是網域或電腦上的有效使用者帳戶名稱: DOMAIN\account

適用於