I'm attempting to configure a site in IIS on Windows 2016 using appcmd.exe. Specifically PHP and FastCGI. I'm running into an issue where specifying the arguments parameter with single quotes fails. I can't seem to figure out how to escape this or what incantation of quotes is required. Here's the command the does work:

%windir%\system32\inetsrv\appcmd.exe set config /section:system.webServer/fastCGI /+"[fullPath='c:\php\php-cgi.exe', arguments='-d open_basedir=E:\Web\www.example.com;E:\Sessions\www.example.com;E:\Logs\www.example.com;E:\Temp\www.example.com', maxInstances='0', instanceMaxRequests='10000']" /commit:apphost

With open_basedir on Windows I need

-d open_basedir=E:\Web\www.example.com;E:\Sessions\www.example.com;E:\Logs\www.example.com;E:\Temp\www.example.com

to be enclosed in single quotes. Like this:

-d open_basedir='E:\Web\www.example.com;E:\Sessions\www.example.com;E:\Logs\www.example.com;E:\Temp\www.example.com'

If I create the FastCGI application first without arguments, I can add them afterwards like this:

%windir%\system32\inetsrv\appcmd.exe set config /section:system.webServer/fastCGI /[fullPath='c:\php\php-cgi.exe'].arguments:"-d open_basedir='E:\Web\www.example.com;E:\Sessions\www.example.com;E:\Logs\www.example.com;E:\Temp\www.example.com'" /commit:apphost

This issue is that I can't change additional settings afterwards because I can't specify the single quoted path with appcmd.

I can accomplish this with the IIS Manager GUI and via C# code. So it's definitely possible to set it this way. I just can't seem to get the correct format for appcmd.

  • 1
    AppCmd.exe is a legacy program, have you considered using PowerShell to configure IIS? You can also try to use Configuration Editor in the GUI to make your changes and then have a look at the generated AppCmd command using the Generate Script dialog. Jan 24, 2018 at 16:08
  • I realize it's older, but it's still supported as far as I can tell. It's also scattered through many scripts in the organization. I didn't really want to rewrite everything in PowerShell. FWIW, appcmd has the same single quote issue on 2008 R2.
    – Deviation
    Jan 24, 2018 at 17:12

2 Answers 2


You use two single quotes to indicate a single quote in a string, for example

C:\Windows\System32\inetsrv\appcmd.exe set config  -section:system.webserver/httpProtocol /+"customHeaders.[name='Content-Security-Policy',value='default-src ''self'';']"

I ran across your question while trying to find the same answer. I discovered a workaround and wanted to let you know.

Use the XML i/o feature of appcmd.exe. On a site with the proper headers, run appcmd list config /section:httpProtocol /xml > addheaders.xml and save the output file. On another system, you can run appcmd set config /in < addheaders.xml

I'm sure you can find a way to include the xml inside the script if you don't want to rely on an extra file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.