I create an installer and during installation the user is asked for the install path.
If the user enters a path that contains spaces, then I can get the uninstaller to run, but at the end of the uninstall process, all the features that should have been removed have not been.
The user is asked for the install directory as follows:
<directoryParameter name="installdirOrig"
default="${platform_install_prefix}/${project.vendor}/${product_shortname}"
ask="yes"
mustBeWritable="yes"
mustExist="0"
width="40">
<validationActionList>
<!-- Replace space with '+', then in scripts revert '+' to space -->
<setInstallerVariableFromRegEx name="installdir"
pattern=" "
text="${installdirOrig}"
substitution="+"/>
<globalVariables names="installdir"/>
</validationActionList>
</directoryParameter>
The install path has spaces replaced by '+' and the scripts that use the install path revert '+' to space
During uninstall I run a number of powershell scripts initiated from functions.
A typical example is to ask for the user password as follows:
<runProgram program="cmd.exe"
showMessageOnError="0"
abortOnError="0">
<programArguments>/C "${msg(PowershellTemplate)} -File ${installdirOrig.dos}/scripts/validate-credentials.ps1 ${accessUsername} ${accessDomain} ${accessPassword.password} &" </programArguments>
</runProgram>
where ${msg(PowershellTemplate)} is defined as:
PowershellTemplate=powershell.exe -ExecutionPolicy Unrestricted -NonInteractive -WindowStyle Hidden
I've used ${installdirOrig.dos} so that spaces will be handled correctly
However, the uninstall log has entries like
Validate the user credentials
Executing cmd.exe /C "powershell.exe -ExecutionPolicy Unrestricted -NonInteractive -WindowStyle Hidden -File C:\PROGRA~1\InstallPath\Path with spaces/scripts/validate-credentials.ps1 username domain **** &"
Script exit code: 0
It looks like 'Program Files' has been altered, but 'Path with spaces' has not
All of the scripts that are executed in this manner return a script exit code of 0, but when the install path contains spaces, not everything is removed as expected by the uninstaller. In contrast, when the install path does NOT contain spaces, everything is removed as expected by the uninstaller.
The &
at the end of the arguments was found to be necessary, otherwise the scripts failed with:
child killed: unknown signal
I'm not sure exactly what is happening, but because there are spaces in the -File switch to the powershell.exe
command, then I'm guessing that the remainder are treated as parameters.
How can I correctly handle a path with spaces during uninstall ?
Thanks for any help