I’m currently looking at using IIS Administration as a way to automate some deployment tasks. However, the way it got installed, it’s appsettings.json
file could not be written to, even when running the text editor as Administrator.
It turns out, SYSTEM had full control of the file, and the installer configured it to only allow me to access the ReST API, yet I needed a deployment script running from the Continuous Delivery server to be able to access IIS Administration, so I needed to modify the settings file, somehow.
To take ownership – The quick guide
So, to take ownership of the appsettings.json
file, what I needed was to run two commands at command prompt running as Administrator.
takeown /f "appsettings.json" /a icacls "appsettings.json" /grant administrators:F /c /l
TAKEOWN
/f [filename]
: Specifies the file or directory name, can contain wildcards.
/a
: Optional, gives the ownership to the Administrators group, rather than the current user.
ICACLS
/grant [sid]:[permission]
: Where sid
is the name of the user or group, and [permission] is the permission set, in this case F
for “full access”
/C
: Indicates to continue on error
/L
: Indicates the operation will run on the symbolic link itself, rather than the target of the link.
And would you believe it, after figuring this out for myself in a generic manner, I find a GitHub issue for the exact scenario on the project I had issues with: https://github.com/Microsoft/IIS.Administration/issues/180