FileSystemSecurity.SetAccessRule(FileSystemAccessRule) Method

Definition

設定目前檔案或目錄之指定的存取控制清單 (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)

Parameters

rule
FileSystemAccessRule

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

Exceptions

rule 參數是 nullThe rule parameter is null.

Remarks

SetAccessRule 方法會新增指定的存取控制清單(ACL)規則,或覆寫任何符合 rule 參數之 FileSystemRights 值的相同 ACL 規則。The 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 方法找到指定 Read 值的相同 ACL 規則,則會覆寫相同的規則。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 方法找到指定 Write 值的相同 ACL 規則,將不會覆寫相同的規則。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.

Applies to