I need to create a small C# Windows app which copies security permissions from one folder to another. That includes copying group permissions too. What would be the best way to approach such a challenge?
Yosief Kesete
So, it need this additional step (on Windows 10): Folder properties > Security tab > Advanced > Permission = Check the box at "Replace all child object permission entries with inheritable permission entries from this object" Icacls /save then Icacls /restore actually also work.
We will copy the permission from one folder to another using Get-ACL of the source and Set-ACL to the destination path using the pipeline. Once the above operation is done, you can check the permission on the destination path. You can see the delta user permission is added and other permissions are also copied.
To copy file permissions from one file to another file, use chmod command with the --reference switch in the following syntax, where reference_file is the file from which permissions will be copied rather than specifying mode (i.e octal or numerical mode permissions) for file.
Rather than writing the whole thing yourself, why don't you get your app to run a tool like AccessChk (use the -l
parameter), and then apply permissions to the target folder based on the info you parse from the output of AccessChk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With