/// <summary> /// 从指定的文件或目录移除访问权限。 /// </summary> /// <param name="path">文件或目录路径。</param> /// <param name="identity">Windows 用户或组名称。</param> /// <param name="fileSystemRights"></param> /// <param name="accessControlType">指定允许还是拒绝该操作。</param> public static void RemovePermission(string path, string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AccessControlType accessControlType) { System.Security.AccessControl.FileSystemAccessRule ar1 = new System.Security.AccessControl.FileSystemAccessRule(identity, fileSystemRights, accessControlType); if (System.IO.Directory.Exists(path)) { System.Security.AccessControl.DirectorySecurity ds = System.IO.Directory.GetAccessControl(path); ds.RemoveAccessRuleAll(ar1); System.IO.Directory.SetAccessControl(path, ds); } else if (System.IO.File.Exists(path)) { System.Security.AccessControl.FileSecurity ds = System.IO.File.GetAccessControl(path); ds.RemoveAccessRuleAll(ar1); System.IO.File.SetAccessControl(path, ds); } }