FileSystemSecurity.SetAccessRule(FileSystemAccessRule) 方法

定義

設定目前檔案或目錄之指定的存取控制清單 (ACL) 使用權限。Sets the specified access control list (ACL) permission for the current file or directory.

public:
 void SetAccessRule(System::Security::AccessControl::FileSystemAccessRule ^ rule);
public void SetAccessRule (System.Security.AccessControl.FileSystemAccessRule rule);
override this.SetAccessRule : System.Security.AccessControl.FileSystemAccessRule -> unit
Public Sub SetAccessRule (rule As FileSystemAccessRule)

參數

rule
FileSystemAccessRule

FileSystemAccessRule 物件,表示要為檔案或目錄設定的存取控制清單 (ACL) 使用權限。A FileSystemAccessRule object that represents an access control list (ACL) permission to set for a file or directory.

例外狀況

rule 參數為 nullThe rule parameter is null.

備註

SetAccessRule方法會將指定的存取控制清單新增 (ACL) 規則,或覆寫符合參數值的任何相同 ACL 規則 FileSystemRights ruleThe SetAccessRule method adds the specified access control list (ACL) rule or overwrites any identical ACL rules that match the FileSystemRights value of the rule parameter. 例如,如果 rule 參數指定 Read 值,而且 SetAccessRule 方法找到指定值的相同 ACL 規則 Read ,則會覆寫相同的規則。For example, if the rule parameter specifies a Read value and the SetAccessRule method finds an identical ACL rule that specifies the Read value, the identical rule will be overwritten. 如果此 SetAccessRule 方法找到指定值的相同 ACL 規則 Write ,則不會覆寫相同的規則。If the SetAccessRule method finds an identical ACL rule that specifies the Write value, the identical rule will not be overwritten.

若要將新的或變更的 ACL 資訊保存到檔案中,請使用 SetAccessControlSetAccessControl 方法。To persist new or changed ACL information to a file, use the SetAccessControl or SetAccessControl method. 若要將新的或變更的 ACL 資訊保存到目錄中,請使用 SetAccessControlSetAccessControl 方法。To persist new or changed ACL information to a directory, use the SetAccessControl or SetAccessControl method.

若要從檔案取出 ACL 資訊,請使用 GetAccessControlGetAccessControl 方法。To retrieve ACL information from a file, use the GetAccessControl or GetAccessControl method. 若要從目錄中取出 ACL 資訊,請使用 GetAccessControlGetAccessControl 方法。To retrieve ACL information from a directory, use the GetAccessControl or GetAccessControl method.

適用於