Tag: file permissions

更改文件夹的权限

我想将一些文件夹权限(设置为只读)更改为ReadWriteExecute! 我写了这段代码,但文件夹权限仍然是只读的: private void ChangePermissions(string folder) { string userName = Environment.UserName; FileSystemAccessRule accessRule = new FileSystemAccessRule(userName, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); DirectoryInfo directoryInfo = new DirectoryInfo(folder); DirectorySecurity directorySec = directoryInfo.GetAccessControl(); directorySec.AddAccessRule(accessRule); directoryInfo.SetAccessControl(directorySec); } 如果我想用Directory.Delete(folder, true)删除此目录,我收到此错误消息: “拒绝访问路径’条目’。” 当然,权限仍然是只读的! 这有什么不对?

如何在.NET Core中修改文件访问控制

我正在尝试更改.NET Core中文件的权限。 但是,似乎FileInfo不再具有任何SetAccessControl 。 // Create a new FileInfo object. FileInfo fInfo = new FileInfo(FileName); // Get a FileSecurity object that represents the // current security settings. FileSecurity fSecurity = fInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings. fSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType)); // Set the new access settings. fInfo.SetAccessControl(fSecurity); 目标只是将执行权添加到文件的当前所有者(不是Windows或Unix特定function)。 有关如何在.NET Core上执行此操作的任何线索?

获取具有“损坏”权限的文件的所有权

我正在努力克服以下情况。 给定存储在NTFS卷上的目录,其中: 目录所有者设置为其他人(例如,非特权用户) 目录DACL配置为允许访问不包括系统或管理员的特定人员组 目录上的DACL实际上不授予任何人获取所有权或更改DACL的权限 (或者简而言之,所有管理员都被锁定在文件夹之外) 但! 我运行的帐户具有管理权限(SeBackupPrivilege,SeSecurityPrivilege) 现在的DACL可以被忽略,因为我正在编写一个新的DACL 使用其他工具(takeown.exe),我可以访问相关目录。 (或者简而言之,我有权修复DACL /所有者) 我对以下代码应该没有问题: WindowsIdentity privilegedUser = System.Security.Principal.WindowsIdentity.GetCurrent(); // I cannot use File.GetAccessControl() as I get access denied // (working as intended! I have no access to read the ACL!) // so I have to write a new ACL: FileSecurity acl = new FileSecurity(); acl.SetOwner(admin.User); acl.AddAccessRule(new […]