3

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?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
zeus
  • 12,173
  • 9
  • 63
  • 184
  • There is nothing built in to Delphi for this. You can use `SetNamedSecurityInfo()` to update the directory's security descriptor with desired user permissions. – Remy Lebeau Jul 06 '18 at 00:43

1 Answers1

8

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.

Paul Sanders
  • 24,133
  • 4
  • 26
  • 48