我想拒绝C#中特定文件夹的写入权限,我找到了检查权限和允许权限的方法。
DirectoryInfo dInfo = new DirectoryInfo(fullPath);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule("everyone", FileSystemRights.FullControl,
InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,
但是没有方法可以检查或拒绝C#
中的权限尝试了这段代码,但我想让管理员拥有对文件夹的完全访问权限。
DirectoryInfo dInfo = new DirectoryInfo(@"C:\New folder\New folder");
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
FileSystemRights.Write, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,
PropagationFlags.NoPropagateInherit, AccessControlType.Deny));
dInfo.SetAccessControl(dSecurity);