How to set ACLs from C # list

How can I automate the following manual steps in C #?

  • Right-click the folder in Windows Explorer;

    Properties -> Security -> Advanced -> Edit

  • Uncheck the box "Enable inherited permissions from this parent of the object" and click "Delete."

  • Click "Add", select a group and give it the right to change.

I found this article that looks exactly what I need, but I don’t and cannot find Microsoft.Win32.Security.

+3
source share
3 answers

check the code below:

DirectoryInfo dInfo = new DirectoryInfo(strFullPath);

DirectorySecurity dSecurity = dInfo.GetAccessControl();

//check off & copy inherited security setting 
dSecurity.SetAccessRuleProtection(true, true); 

dInfo.SetAccessControl(dSecurity);

http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.objectsecurity.setaccessruleprotection.aspx

and to set permissions for the folder:

http://www.redmondpie.com/applying-permissions-on-any-windows-folder-using-c/

+3

, DirectorySecurity System.Security.AccessControl namespace.

, , , InheritanceFlags .

+1

, ACL .Net Standard 2.0, , :

Microsoft.Windows.Compatibility -Version 2.0.1 Microsoft.DotNet.Analyzers.Compatibility -Version 0.2.12-alpha

, , .Net Framework. , , , , Linux MacOS

 DirectoryInfo dInfo = new DirectoryInfo(strFullPath);
 DirectorySecurity dSecurity = dInfo.GetAccessControl();
 //check off & copy inherited security setting 
 dSecurity.SetAccessRuleProtection(true, true); 
 dInfo.SetAccessControl(dSecurity);

For more information, see https://github.com/dotnet/docs/blob/master/docs/core/porting/windows-compat-pack.md.

0
source

Source: https://habr.com/ru/post/1762824/


All Articles