/// <summary> /// 从指定的文件或目录移除访问权限。 /// </summary> /// <param name="path">文件或目录路径。</param> /// <param name="identity">Windows 用户或组名称。</param> public static void RemovePermission(string path, string identity) { if (System.IO.Directory.Exists(path)) { System.Security.AccessControl.DirectorySecurity ds = System.IO.Directory.GetAccessControl(path); ds.PurgeAccessRules(new System.Security.Principal.NTAccount(identity)); System.IO.Directory.SetAccessControl(path, ds); } else if (System.IO.File.Exists(path)) { System.Security.AccessControl.FileSecurity ds = System.IO.File.GetAccessControl(path); ds.PurgeAccessRules(new System.Security.Principal.NTAccount(identity)); System.IO.File.SetAccessControl(path, ds); } }