Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding IIS_IUSRS with write permission to a directory programmatically

I'm using Delphi 10.2 Tokyo, and I would like to add write permissions for the IIS_IUSRS user to a specific directory.

Are there any built-in functions in Delphi that I can use to do this?

If not, what are the Win32 API functions I must use?

like image 276
zeus Avatar asked Oct 20 '25 03:10

zeus


1 Answers

Doing this programatically is a pain because of the complexity of the Windows security APIs, but there is an easier way, and that is to shell out to icacls and have that do the heavy lifting instead.

I don't know how you get Delphi to run a command line program but I imagine you can handle that bit, so a suitable command line is probably something like:

icacls MyFolder /grant "IIS_IUSRS:(OI)(CI)F"

This grants 'full access' to MyFolder and all who sail in her, and you can inspect exactly what effect this (or some other) command has actually had via the 'Security' tab in the Properties window for the folder in question in Explorer.

Other, more fine-grained permissions are possible, there's a useful post here:

How to grant permission to users for a directory using command line in Windows?

Happy ACL twiddling.

like image 122
Paul Sanders Avatar answered Oct 22 '25 05:10

Paul Sanders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!