FileSystemSecurity 類別

定義

表示檔案或目錄的存取控制 (Access Control) 和稽核安全性。

public ref class FileSystemSecurity abstract : System::Security::AccessControl::NativeObjectSecurity
public abstract class FileSystemSecurity : System.Security.AccessControl.NativeObjectSecurity
[System.Security.SecurityCritical]
public abstract class FileSystemSecurity : System.Security.AccessControl.NativeObjectSecurity
type FileSystemSecurity = class
    inherit NativeObjectSecurity
[<System.Security.SecurityCritical>]
type FileSystemSecurity = class
    inherit NativeObjectSecurity
Public MustInherit Class FileSystemSecurity
Inherits NativeObjectSecurity
繼承
衍生
屬性

範例

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

備註

類別 FileSystemSecurity 是 和 DirectorySecurity 類別的 FileSecurity 基類。 這些類別代表系統檔案或目錄的所有存取權限,並定義如何稽核存取嘗試。

類別 FileSystemSecurity 會將存取權和稽核許可權表示為一組規則。 每個存取規則都是由 FileSystemAccessRule 物件表示,而每個稽核規則則以 FileSystemAuditRule 物件表示。

類別 FileSystemSecurity 是基礎 Microsoft Windows檔案系統的抽象概念。 在此系統中,每個檔案或目錄都有一個選擇性存取控制清單 (DACL) ,可控制檔案或目錄的存取權,而系統存取控制清單 (SACL) ,這會指定稽核的存取控制嘗試。 FileSystemAccessRuleFileSystemAuditRule 類別是存取控制專案的抽象概念, (ACE) 組成 DACL 和 SCL。

類別 FileSystemSecurity 會隱藏 DACL 和 SCL 的許多詳細資料;您不需要擔心 ACE 排序或 Null DACLS。

若要將新的或變更的存取控制清單保存 (ACL) 資訊至檔案,請使用 SetAccessControlSetAccessControl 方法。 若要將新的或變更的 ACL 資訊保存到目錄,請使用 SetAccessControlSetAccessControl 方法。

若要從檔案擷取 ACL 資訊,請使用 GetAccessControlGetAccessControl 方法。 若要從目錄擷取 ACL 資訊,請使用 GetAccessControlGetAccessControl 方法。

屬性

AccessRightType

取得 FileSystemSecurity 類別用來表示存取權限的列舉型別 (Enumeration)。

AccessRulesModified

取得或設定布林值,指定是否已修改與這個 ObjectSecurity 物件關聯的存取規則。

(繼承來源 ObjectSecurity)
AccessRuleType

取得 FileSystemSecurity 類別用來表示存取規則的列舉型別。

AreAccessRulesCanonical

取得布林值,指定與這個 ObjectSecurity 物件相關聯的存取規則是否為標準順序。

(繼承來源 ObjectSecurity)
AreAccessRulesProtected

取得布林值,指定是否保護與這個 ObjectSecurity 物件相關聯的判別存取控制清單 (DACL)。

(繼承來源 ObjectSecurity)
AreAuditRulesCanonical

取得布林值,指定與 ObjectSecurity 物件相關聯的稽核規則是否為標準順序。

(繼承來源 ObjectSecurity)
AreAuditRulesProtected

取得布林值,指定是否保護與這個 ObjectSecurity 物件相關聯的系統存取控制清單 (SACL)。

(繼承來源 ObjectSecurity)
AuditRulesModified

取得或設定布林值,指定是否已修改與這個 ObjectSecurity 物件關聯的稽核規則。

(繼承來源 ObjectSecurity)
AuditRuleType

取得 FileSystemSecurity 類別用來表示稽核規則的類型。

GroupModified

取得或設定布林值,指定是否已修改與安全物件關聯的群組。

(繼承來源 ObjectSecurity)
IsContainer

取得可指定這個 ObjectSecurity 物件是否為容器物件的布林值。

(繼承來源 ObjectSecurity)
IsDS

取得可指定這個 ObjectSecurity 物件是否為目錄物件的布林值。

(繼承來源 ObjectSecurity)
OwnerModified

取得或設定布林值,指定是否已修改安全物件的擁有者。

(繼承來源 ObjectSecurity)
SecurityDescriptor

取得此執行個體的安全性描述元。

(繼承來源 ObjectSecurity)

方法

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

以指定的存取權限、存取控制和旗標,初始化 FileSystemAccessRule 類別 (用於表示指定使用者的新存取控制規則) 的新執行個體。

AddAccessRule(AccessRule)

將指定的存取規則加入與這個 CommonObjectSecurity 物件相關聯的 Discretionary 存取控制清單 (DACL)。

(繼承來源 CommonObjectSecurity)
AddAccessRule(FileSystemAccessRule)

將指定的存取控制清單 (ACL) 使用權限加入至目前的檔案或目錄。

AddAuditRule(AuditRule)

將指定的稽核規則加入與這個 CommonObjectSecurity 物件相關聯的系統存取控制清單 (SACL)。

(繼承來源 CommonObjectSecurity)
AddAuditRule(FileSystemAuditRule)

將指定的稽核規則加入至目前的檔案或目錄。

AuditRuleFactory(IdentityReference, Int32, Boolean, InheritanceFlags, PropagationFlags, AuditFlags)

初始化 FileSystemAuditRule 類別 (表示指定之使用者的指定稽核規則) 的新執行個體。

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 物件相關聯之安全性描述元的指定區段儲存到永久儲存區。 建議傳遞至建構函式和保存方法之 includeSections 參數的值應完全相同。

(繼承來源 ObjectSecurity)
Persist(SafeHandle, AccessControlSections)

將與這個 NativeObjectSecurity 物件相關聯之安全性描述元的指定區段儲存到永久儲存區。 建議您保留傳遞到建構函式的 includeSections 參數值,並維持方法相同。

(繼承來源 NativeObjectSecurity)
Persist(SafeHandle, AccessControlSections, Object)

將與這個 NativeObjectSecurity 物件相關聯之安全性描述元的指定區段儲存到永久儲存區。 建議傳遞至建構函式和保存方法之 includeSections 參數的值應完全相同。

(繼承來源 NativeObjectSecurity)
Persist(String, AccessControlSections)

將與這個 NativeObjectSecurity 物件相關聯之安全性描述元的指定區段儲存到永久儲存區。 建議傳遞至建構函式和保存方法之 includeSections 參數的值應完全相同。

(繼承來源 NativeObjectSecurity)
Persist(String, AccessControlSections, Object)

將與這個 NativeObjectSecurity 物件相關聯之安全性描述元的指定區段儲存到永久儲存區。 建議傳遞至建構函式和保存方法之 includeSections 參數的值應完全相同。

(繼承來源 NativeObjectSecurity)
PurgeAccessRules(IdentityReference)

移除與指定之 IdentityReference 相關聯的所有存取規則。

(繼承來源 ObjectSecurity)
PurgeAuditRules(IdentityReference)

移除與指定之 IdentityReference 相關聯的所有稽核規則。

(繼承來源 ObjectSecurity)
ReadLock()

鎖定這個 ObjectSecurity 物件的讀取權限。

(繼承來源 ObjectSecurity)
ReadUnlock()

解除鎖定這個 ObjectSecurity 物件的讀取權限。

(繼承來源 ObjectSecurity)
RemoveAccessRule(AccessRule)

從與這個 CommonObjectSecurity 物件相關聯的 Discretionary 存取控制清單 (DACL),移除包含與指定存取規則相同安全識別項和存取遮罩的存取規則。

(繼承來源 CommonObjectSecurity)
RemoveAccessRule(FileSystemAccessRule)

從目前的檔案或目錄中,移除所有相符的允許或拒絕存取控制清單 (ACL) 使用權限。

RemoveAccessRuleAll(AccessRule)

從與這個 CommonObjectSecurity 物件相關聯的 Discretionary 存取控制清單 (DACL),移除包含與指定存取規則相同安全識別項的所有存取規則。

(繼承來源 CommonObjectSecurity)
RemoveAccessRuleAll(FileSystemAccessRule)

從目前的檔案或目錄中,移除指定之使用者的所有存取控制清單 (ACL) 使用權限。

RemoveAccessRuleSpecific(AccessRule)

從與這個 CommonObjectSecurity 物件相關聯的 Discretionary 存取控制清單 (DACL),移除與指定存取規則完全相符的所有存取規則。

(繼承來源 CommonObjectSecurity)
RemoveAccessRuleSpecific(FileSystemAccessRule)

從目前的檔案或目錄中,移除相符的單一允許或拒絕存取控制清單 (ACL) 使用權限。

RemoveAuditRule(AuditRule)

從與這個 CommonObjectSecurity 物件相關聯的系統存取控制清單 (SACL),移除包含與指定稽核規則相同安全識別項和存取遮罩的稽核規則。

(繼承來源 CommonObjectSecurity)
RemoveAuditRule(FileSystemAuditRule)

從目前的檔案或目錄中,移除所有相符的允許或拒絕稽核規則。

RemoveAuditRuleAll(AuditRule)

從與這個 CommonObjectSecurity 物件相關聯的系統存取控制清單 (SACL),移除包含與指定稽核規則相同安全識別項的所有稽核規則。

(繼承來源 CommonObjectSecurity)
RemoveAuditRuleAll(FileSystemAuditRule)

從目前的檔案或目錄中,移除指定之使用者的所有稽核規則。

RemoveAuditRuleSpecific(AuditRule)

從與這個 CommonObjectSecurity 物件相關聯的系統存取控制清單 (SACL),移除與指定稽核規則完全相符的所有稽核規則。

(繼承來源 CommonObjectSecurity)
RemoveAuditRuleSpecific(FileSystemAuditRule)

從目前的檔案或目錄中,移除相符的單一允許或拒絕稽核規則。

ResetAccessRule(AccessRule)

移除與這個 CommonObjectSecurity 物件相關聯之 Discretionary 存取控制清單 (DACL) 中的所有存取規則,然後加入指定的存取規則。

(繼承來源 CommonObjectSecurity)
ResetAccessRule(FileSystemAccessRule)

將指定的存取控制清單 (ACL) 使用權限加入至目前的檔案或目錄,並移除所有相符的 ACL 使用權限。

SetAccessRule(AccessRule)

從與這個 CommonObjectSecurity 物件相關聯之 Discretionary 存取控制清單 (DACL),移除包含與指定存取規則相同安全識別項和限定詞的所有存取規則,然後加入指定的存取規則。

(繼承來源 CommonObjectSecurity)
SetAccessRule(FileSystemAccessRule)

設定目前檔案或目錄之指定的存取控制清單 (ACL) 使用權限。

SetAccessRuleProtection(Boolean, Boolean)

設定或移除與 ObjectSecurity 物件相關聯的存取規則保護。 受保護的存取規則無法透過繼承來由父物件所修改。

(繼承來源 ObjectSecurity)
SetAuditRule(AuditRule)

從與這個 CommonObjectSecurity 物件相關聯之系統存取控制清單 (SACL),移除包含與指定稽核規則相同安全識別項和限定詞的所有稽核規則,然後加入指定的稽核規則。

(繼承來源 CommonObjectSecurity)
SetAuditRule(FileSystemAuditRule)

設定目前檔案或目錄的指定稽核規則。

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)

適用於