FileSystemAccessRule 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示為檔案或目錄定義存取規則之存取控制項目 (ACE) 的抽象。 此類別無法獲得繼承。
public ref class FileSystemAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class FileSystemAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class FileSystemAccessRule : System.Security.AccessControl.AccessRule
type FileSystemAccessRule = class
inherit AccessRule
[<System.Security.SecurityCritical>]
type FileSystemAccessRule = class
inherit AccessRule
Public NotInheritable Class FileSystemAccessRule
Inherits AccessRule
- 繼承
- 屬性
範例
下列程式碼範例會 FileSecurity 使用 類別,從檔案中新增和移除 ACE) (存取控制專案。 您必須提供有效的使用者或群組帳戶,才能執行這個範例。
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
備註
類別 FileSystemAccessRule 代表基礎存取控制專案的抽象概念, (ACE) 指定使用者帳戶、提供 (讀取、寫入) 等 (的存取類型,以及是否允許或拒絕該許可權。 這個類別也可以指定存取規則如何傳播至子物件。
使用 類別 FileSystemAccessRule 來建立新的存取規則。 您可以使用 或 DirectorySecurity 類別來保存規則 FileSecurity 。
建構函式
FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType) |
使用對使用者帳戶的參考、指定與存取規則關聯之作業類型的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。 |
FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType) |
使用對使用者帳戶的參考、指定與存取規則關聯之作業類型的值、判斷如何繼承權限的值、判斷如何散佈權限的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。 |
FileSystemAccessRule(String, FileSystemRights, AccessControlType) |
利用使用者帳戶的名稱、指定與存取規則關聯之作業類型的值,以及描述允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。 |
FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType) |
利用使用者帳戶的名稱、指定與存取規則關聯之作業類型的值、判斷如何繼承權限的值、判斷如何散佈權限的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。 |
屬性
AccessControlType |
取得與這個 AccessControlType 物件相關聯的 AccessRule 值。 (繼承來源 AccessRule) |
AccessMask |
取得此規則的存取遮罩。 (繼承來源 AuthorizationRule) |
FileSystemRights |
取得與目前 FileSystemRights 物件關聯的 FileSystemAccessRule 旗標。 |
IdentityReference |
取得要套用此規則的 IdentityReference。 (繼承來源 AuthorizationRule) |
InheritanceFlags |
取得旗標值,這個值會決定子物件繼承這項規則的方式。 (繼承來源 AuthorizationRule) |
IsInherited |
取得值,表示這個規則是否會明確地設定或繼承自父容器物件。 (繼承來源 AuthorizationRule) |
PropagationFlags |
取得傳播旗標的值,該值判斷這個規則的繼承如何傳播到子物件。 只有當 InheritanceFlags 列舉的值不是 None,這個屬性才是重要的。 (繼承來源 AuthorizationRule) |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |