How to escape quotes when passing custom public properties to an MSI through an EXE?
Hi, there's a million questions like this but I've been googling all day and can't figure this one out.
As usual I'm stuck trying to automate the deployment of some engineering software with janky installers. I need to pass custom properties to an MSI installer, and I must call the MSI through an EXE. I have been unable to find the appropriate syntax for escaping quotes when passing custom properties to the MSI.
The following command line works, with no values needing quotes:
.\setup.exe /S /v"/qr /norestart /l* c:\install.log AgreeToLicense=Yes CUSTOMPROP=simplevalue REBOOT=ReallySuppress"
The following command line also works, with two double-quotes escaping a value that doesn't actually need it:
.\setup.exe /S /v"/qr /norestart /l* c:\install.log AgreeToLicense=Yes CUSTOMPROP=""simplevalue"" REBOOT=ReallySuppress"
However the following command line does not work, putting actual spaces in the supposedly escaped value. The EXE successfully runs, and the MSI doesn't complain about syntax, but the MSI still doesn't function and never even outputs a log:
.\setup.exe /S /v"/qr /norestart /l* c:\install.log AgreeToLicense=Yes CUSTOMPROP=""value with spaces"" REBOOT=ReallySuppress"
I need to pass a custom value with spaces to define (among other things) the install directory for the MSI, which must have spaces (i.e. "C:\Program Files (x86)\Janky Jank\"). So can anyone tell me what the proper way to escape these values would be in a commandline like this? For what it's worth, I've mostly just been testing in a powershell 5.1 prompt, though I've tried a regular command prompt as well. However the ultimate goal is to package this as an application in MECM if at all possible. I'm not averse to using a custom script as an install method to achieve that.
Any suggestions are much appreciated. I've tried eleven ways to sunday with different combinations and quantities of quotes, backslashes, etc.
Thanks,
Answers (1)
Top Answer
I finally figured it out. The following works as intended:
.\setup.exe /S /v"/qr /norestart /l* c:\install.log AgreeToLicense=Yes CUSTOMPROP=\""value with spaces\"" REBOOT=ReallySuppress"
Although when the value itself ends with a backslash (e.g. CUSTOMPROP=\""c:\path\\""), I've found that I need to include a second backslash to escape the trailing backslash of the path, for a total of 3 consecutive backslashes. Otherwise the path's trailing backslash just escapes the backslash used for the quotes, i.e.:
.\setup.exe /S /v"/qr /norestart /l* c:\install.log AgreeToLicense=Yes CUSTOMPROP=\""c:\path\\\"" REBOOT=ReallySuppress"
That being said I don't understand why it works, or why it didn't work without the single backslashes, or with more backslashes between characters. But after 3 days of futzing I don't care anymore. My guess is that the pairs of double quotes ("") are being treated as a single character, so \"" is actually a single escaped character.