Disable inheritance on a folder NTFS permissions in C#

瘦欲@ 提交于 2021-01-28 16:51:38

问题


How can I disable inheritance on a folder and delete all inherited permissions

Thank you

I tried this :

DirectoryInfo dInfo = new DirectoryInfo(path);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.SetAccessRuleProtection(false, false);

回答1:


If someone search the solution :

        DirectorySecurity directorySecurity = Directory.GetAccessControl(path);
        directorySecurity.SetAccessRuleProtection(true, keepPermissions);
        Directory.SetAccessControl(path, directorySecurity);

with keepPermissions true if you want to keep inherited permissions.



来源:https://stackoverflow.com/questions/34162619/disable-inheritance-on-a-folder-ntfs-permissions-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!