PowerShell - paths with spaces - Advanced Installer Community
williamssi
Posts: 4
Joined: Tue Sep 20, 2016 8:39 pm

PowerShell - paths with spaces

I have a Custom Action "Run PowerShell Inline Script" from which I want to run a batch file from a specific working directory, i.e.

Code: Select all

$serviceDir = AI_GetMsiProperty service_Dir
Start-Process -FilePath "run.bat" -WorkingDirectory $serviceDir
However, if the directory has a space, e.g. "Program Files" an error is thrown when the space is hit.
I have tried forcing additional single or double quotes around the string:

Code: Select all

Start-Process -FilePath "run.bat" -WorkingDirectory "'$serviceDir'"
But that results in the following error log:
Dumping PowerShell invoke log ...
--> Found PowerShell path: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
--> PowerShell Script Execution Result Code: 574
--> PowerShell Script Execution log:
Start-Process -FilePath "run.bat" -WorkingDirectory C:\Program Files\Test\service\
C:\Users\IEUser\AppData\Local\Temp\pss2AB4.ps1 : Caught Exception: Cannot find drive. A drive with the name ''C' does not exist.
+ CategoryInfo : NotSpecified: (:) , WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,pss2AB4.ps1
It appears it does not like the leading quote

The same code appears to work from the PowerShell command line, i.e. outside of Advanced Installer

Any help would be greatly appreciated.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: PowerShell - paths with spaces

Hello and welcome to our forums,

I've tested your installation scenario on a Windows 10 x64 machine and the inline PowerShell action successfully launched the BAT file when used the following script without quotes around $serviceDir variable:

Code: Select all

$serviceDir = AI_GetMsiProperty service_Dir
Start-Process -FilePath "run.bat" -WorkingDirectory $serviceDir
Can you please test again your installation scenario using the above script? If the installation still fails, please send us the .AIP (project file) and a verbose log of the installation to support at advancedinstaller dot com so we can investigate them.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”