FileSystemAccessRule 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 FileSystemAccessRule 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| 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 錯誤的枚舉結果。
備註
使用這個建構子建立一個存取控制規則,並可透過 FileSecurity or DirectorySecurity 類別持續執行。 存取控制規則定義了使用者帳號權限,決定執行Microsoft Windows電腦允許或禁止哪些動作。
適用於
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 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)
{
FileInfo fileInfo = new(fileName);
FileSecurity fSecurity = fileInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
fileInfo.SetAccessControl(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)
{
FileInfo fileInfo = new(fileName);
FileSecurity fSecurity = fileInfo.GetAccessControl();
// Remove the FileSystemAccessRule from the security settings.
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
fileInfo.SetAccessControl(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)
Dim fileInfo As New FileInfo(fileName)
Dim fSecurity As FileSecurity = fileInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
Dim accessRule As New FileSystemAccessRule(account, rights, controlType)
fSecurity.AddAccessRule(accessRule)
' Set the new access settings.
fileInfo.SetAccessControl(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)
Dim fileInfo As New FileInfo(fileName)
Dim fSecurity As FileSecurity = fileInfo.GetAccessControl()
' Remove the FileSystemAccessRule from the security settings.
fSecurity.RemoveAccessRule(New FileSystemAccessRule(account,
rights, controlType))
' Set the new access settings.
fileInfo.SetAccessControl(fSecurity)
End Sub
End Module
備註
使用這個建構子建立一個存取控制規則,並可透過 FileSecurity or DirectorySecurity 類別持續執行。 存取控制規則定義了使用者帳號權限,決定執行Microsoft Windows電腦允許或禁止哪些動作。
該 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 錯誤的枚舉結果。
備註
使用這個建構子建立一個存取控制規則,並可透過 FileSecurity or DirectorySecurity 類別持續執行。 存取控制規則定義了使用者帳號權限,決定執行Microsoft Windows電腦允許或禁止哪些動作。
適用於
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 錯誤的枚舉結果。
備註
使用這個建構子建立一個存取控制規則,並可透過 FileSecurity or DirectorySecurity 類別持續執行。 存取控制規則定義了使用者帳號權限,決定執行Microsoft Windows電腦允許或禁止哪些動作。
該 identity 參數必須識別目前電腦或網域上的有效帳號。 字串形式如下,其中 DOMAIN 是有效網域或電腦名稱的名稱, account 是網域或電腦上有效使用者帳號的名稱: DOMAIN\account。