PowerShell Custom Action Property Bug - Advanced Installer Community
Howard.vanRooijen
Posts: 2
Joined: Fri Mar 13, 2015 8:33 am

PowerShell Custom Action Property Bug

Hi,

I was building an installer yesterday (using v11.8 of AI) that has a PowerShell Custom Action. I wanted to pass in the value of the installation directory into the script so that it could invoke some other cmdlets that are bundled with the installer.

By default the installation path is C:\Program Files (x86)\MyCompany\MyApp - obviously this has a space in the path that needs to be dealt with. Without wrapping the script parameter property with " " as expected the PowerShell script fails because the file C:\Program cannot be found.

So on the second attempt I tried -installPath "[APPDIR]" but this resulted in the error file C:\Program Files (x86)\MyCompany\MyApp"\MyFile.ps1 cannot be found (note the " between the injected path and the file name).

In order to get the path to be resolved correctly I had to use the following (note the single "):

Script Parameters:
-installPath "[APPDIR]

Script:
param($installPath)
Write-Output $installPath

This feels like a bug, because it's not the behaviour I would expect. Can you confirm if this is an bug or an expected behaviour (I did waste a good couple of hours trying to figure out why this wouldn't work!)

Also it would be really good if your documentation could include a note that you need to add the param($installPath) element for each parameter you want to pass in, it should have been obvious, but it took me a while to figure out why I wasn't seeing anything being passed into the script!

Many thanks,

Howard
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: PowerShell Custom Action Property Bug

Hi Howard and welcome to Advanced Installer forums,

This is happening because our custom action launches the PowerShell script through Windows command interpreter tool (cmd.exe), the above parameter ending character sequence (\") will be escaped to " character, accordingly with cmd.exe character escaping rules. Therefore, instead of being resolved to the C:\Program Files (x86)\Your Company\Your Application\ value, the above parameter will be resolved to C:\Program Files (x86)\Your Company\Your Application".

To avoid this behavior you should duplicate the trailing backslash by adding and extra backslash character just after the APPDIR property formatted reference:

Code: Select all

Script Parameters: -appdirParam "[APPDIR]\"
Also it would be really good if your documentation could include a note that you need to add the param($installPath) element for each parameter you want to pass in, it should have been obvious, but it took me a while to figure out why I wasn't seeing anything being passed into the script!
We already added a note about this behaviour to the Run Windows PowerShell Script help page starting with the next version of Advanced Installer which is scheduled to be released soon.

If you have other questions, please let us know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Howard.vanRooijen
Posts: 2
Joined: Fri Mar 13, 2015 8:33 am

Re: PowerShell Custom Action Property Bug

Hi Dan,

thanks very much for the explanation! Makes a lot of sense. Do you think you could add something to this effect to the help documentation to help future me, once current me has forgotten this gotcha?

Howard
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: PowerShell Custom Action Property Bug

You're welcome Howard,

As I said, the PowerShell custom action will be more documented starting with the next release of Advanced Installer (the User Guide and the Website will be updated).

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”