語言

FileSystemAuditRule 建構函式

定義

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

多載

名稱 Description
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 。

備註

使用這個建構器建立一個審計規則,你可以用 FileSecurity OR DirectorySecurity 類別持續執行。 稽核規則決定何時以及如何記錄對系統物件(如檔案和資料夾)執行的操作。

適用於

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

備註

使用這個建構器建立一個審計規則,你可以用 FileSecurity OR DirectorySecurity 類別持續執行。 稽核規則決定何時以及如何記錄對系統物件(如檔案和資料夾)執行的操作。

該 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 。

備註

使用這個建構器建立一個審計規則,你可以用 FileSecurity OR DirectorySecurity 類別持續執行。 稽核規則決定何時以及如何記錄對系統物件(如檔案和資料夾)執行的操作。

適用於

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其中一個數值會指定何時進行稽核。

備註

使用這個建構器建立一個審計規則,你可以用 FileSecurity OR DirectorySecurity 類別持續執行。 稽核規則決定何時以及如何記錄對系統物件(如檔案和資料夾)執行的操作。

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

適用於