FileSystemAccessRule 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 FileSystemAccessRule 類別的新執行個體。
多載
FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType) |
使用對使用者帳戶的參考、指定與存取規則關聯之作業類型的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。 |
FileSystemAccessRule(String, FileSystemRights, AccessControlType) |
利用使用者帳戶的名稱、指定與存取規則關聯之作業類型的值,以及描述允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。 |
FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType) |
使用對使用者帳戶的參考、指定與存取規則關聯之作業類型的值、判斷如何繼承權限的值、判斷如何散佈權限的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。 |
FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType) |
利用使用者帳戶的名稱、指定與存取規則關聯之作業類型的值、判斷如何繼承權限的值、判斷如何散佈權限的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。 |
FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)
使用對使用者帳戶的參考、指定與存取規則關聯之作業類型的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。
public:
FileSystemAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, type As AccessControlType)
參數
- identity
- IdentityReference
IdentityReference 物件,封裝使用者帳戶的參考。
- fileSystemRights
- FileSystemRights
其中一個 FileSystemRights 值,可指定與存取規則有關聯的作業類型。
- type
- AccessControlType
其中一個 AccessControlType 值,可指定是要允許還是拒絕此作業。
例外狀況
identity
參數不是 IdentityReference 物件。
identity
參數為 null
。
不正確的列舉型別已傳遞至 type
參數。
備註
使用此建構函式來建立您可以使用 或 DirectorySecurity 類別保存的 FileSecurity 存取控制規則。 存取控制規則會定義使用者帳戶許可權,以決定執行 windows Microsoft電腦上允許或不允許執行的動作。
適用於
FileSystemAccessRule(String, FileSystemRights, AccessControlType)
利用使用者帳戶的名稱、指定與存取規則關聯之作業類型的值,以及描述允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。
public:
FileSystemAccessRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, type As AccessControlType)
參數
- identity
- String
使用者帳戶的名稱。
- fileSystemRights
- FileSystemRights
其中一個 FileSystemRights 值,可指定與存取規則有關聯的作業類型。
- type
- AccessControlType
其中一個 AccessControlType 值,可指定是要允許還是拒絕此作業。
例外狀況
identity
參數為 null
。
不正確的列舉型別已傳遞至 type
參數。
範例
下列程式碼範例會 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
備註
使用此建構函式來建立您可以使用 或 DirectorySecurity 類別保存的 FileSecurity 存取控制規則。 存取控制規則會定義使用者帳戶許可權,以決定執行 windows Microsoft電腦上允許或不允許執行的動作。
參數 identity
必須識別目前電腦或網域的有效帳戶。 字串採用下列形式,其中 DOMAIN
是有效網域或電腦名稱稱的名稱,而且 account
是網域或電腦上的有效使用者帳戶名稱: DOMAIN\account
。
適用於
FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)
使用對使用者帳戶的參考、指定與存取規則關聯之作業類型的值、判斷如何繼承權限的值、判斷如何散佈權限的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。
public:
FileSystemAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, type As AccessControlType)
參數
- identity
- IdentityReference
IdentityReference 物件,封裝使用者帳戶的參考。
- fileSystemRights
- FileSystemRights
其中一個 FileSystemRights 值,可指定與存取規則有關聯的作業類型。
- inheritanceFlags
- InheritanceFlags
其中一個 InheritanceFlags 值,可指定存取遮罩要如何散佈到子物件。
- propagationFlags
- PropagationFlags
其中一個 PropagationFlags 值,可指定存取控制項目 (ACE) 要如何散佈到子物件。
- type
- AccessControlType
其中一個 AccessControlType 值,可指定是要允許還是拒絕此作業。
例外狀況
identity
參數不是 IdentityReference 物件。
identity
參數為 null
。
不正確的列舉型別已傳遞至 type
參數。
-或-
不正確的列舉型別已傳遞至 inheritanceFlags
參數。
-或-
不正確的列舉型別已傳遞至 propagationFlags
參數。
備註
使用此建構函式來建立您可以使用 或 DirectorySecurity 類別保存的 FileSecurity 存取控制規則。 存取控制規則會定義使用者帳戶許可權,以決定執行 windows Microsoft電腦上允許或不允許執行的動作。
適用於
FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)
利用使用者帳戶的名稱、指定與存取規則關聯之作業類型的值、判斷如何繼承權限的值、判斷如何散佈權限的值,以及指定允許還是拒絕作業的值,初始化 FileSystemAccessRule 類別的新執行個體。
public:
FileSystemAccessRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, type As AccessControlType)
參數
- identity
- String
使用者帳戶的名稱。
- fileSystemRights
- FileSystemRights
其中一個 FileSystemRights 值,可指定與存取規則有關聯的作業類型。
- inheritanceFlags
- InheritanceFlags
其中一個 InheritanceFlags 值,可指定存取遮罩要如何散佈到子物件。
- propagationFlags
- PropagationFlags
其中一個 PropagationFlags 值,可指定存取控制項目 (ACE) 要如何散佈到子物件。
- type
- AccessControlType
其中一個 AccessControlType 值,可指定是要允許還是拒絕此作業。
例外狀況
identity
參數為 null
。
不正確的列舉型別已傳遞至 type
參數。
-或-
不正確的列舉型別已傳遞至 inheritanceFlags
參數。
-或-
不正確的列舉型別已傳遞至 propagationFlags
參數。
備註
使用此建構函式來建立您可以使用 或 DirectorySecurity 類別保存的 FileSecurity 存取控制規則。 存取控制規則會定義使用者帳戶許可權,以決定執行 windows Microsoft電腦上允許或不允許執行的動作。
參數 identity
必須識別目前電腦或網域的有效帳戶。 字串採用下列形式,其中 DOMAIN
是有效網域或電腦名稱稱的名稱,而且 account
是網域或電腦上的有效使用者帳戶名稱: DOMAIN\account
。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應