PDA

View Full Version : How to run a powershell script from msi before install



DjessHz
02-15-2017, 10:25 AM
Hi,

I'm trying to run a PowerShell script before installing my application via the MSI package
I would like my script to run directly when the user is double clicking on the MSI

I have already tried to do this :

On Behavior and Logic -> Custom actions and Sequences
Custom actions -> New PowerShell -> Stored in Binary Table

On Common table :
PowerShell Script File Name -> Path to my ps1 script
Return Processing -> Synchronous (Check exit code)
In-Script Execution -> Immediate execution
Execution scheduling -> Always execute

Install Exec Sequence -> <First Action>

But my script is not running when my MSI is launched

Did I forgot something ?
Thank you

chad.petersen
02-15-2017, 11:00 AM
The Exec Sequence does not happen until you get all of the way through the UI Sequence. It sounds like you've got it scheduled to run in the wrong sequence for what you are wanting.

Try changing it to the UI Sequence instead.

Chad

DjessHz
02-15-2017, 11:13 AM
The Exec Sequence does not happen until you get all of the way through the UI Sequence. It sounds like you've got it scheduled to run in the wrong sequence for what you are wanting.

Try changing it to the UI Sequence instead.

Chad

I have already tryed to change the UI Sequence, it's not working

Any other idea ?

DjessHz
02-17-2017, 08:35 AM
Ok, I found the problem (really strange by the way...)

My script was not working because it needed another script to work..
As my original script was not working, I created a new one (another powershell script) which was only displaying a form :


[System.Windows.Forms.MessageBox]::Show("My Custom Action","Hello", 0, 64)

I removed my original script from the sequences and I have been trying to run my test script at all positions in the UI and Exec sequences
With no success..

So, I tried to run my first script again, but I forgot to desactivate my test script
And, miraculously, it works !

I don't know if it is an Installshield problem or maybe a wrong defined or forgotten parameter

But the fact is, in order to run a powershell script (before install process in my case) follow these steps:

For the new script
1) Create a new Powershell custom action (in addition to your script)
2) In the common tab :
PowerShell Script File Name -> Path to an empty script ps1
Return Processing -> Synchronous (Check exit code)
In-Script Execution -> Immediate execution
Execution scheduling -> Always execute

Install UI Sequence -> <After LaunchConditions>
Install Exec Sequence -> <First Action>
+ Install Exec Condition -> Not Installed

For your custom script
In the common tab :
PowerShell Script File Name -> Path to your script ps1
Return Processing -> Synchronous (Check exit code)
In-Script Execution -> Immediate execution
Execution scheduling -> Always execute

Install UI Sequence -> <After YourEmptyScript>
Install Exec Sequence -> <After LaunchConditions>
+ Install Exec Condition -> Not Installed

If, for example, you add a form in the new script, it will not be executed, but allows the second one to run..

If someone has an explanation, feel free to share !
Thank you and enjoy