cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
GomochaInstall
Level 5

Let user set InstallShield property during installation, then use that property in PowerShell

Jump to solution

Hello everyone,

I'm trying to implement something in our installer. I'd like the user to set a certain property during the installation. (say, after the License Agreement screen) Once it is time to actually install the software, I will run a 'PowerShell Custom Action' with the 'In-Script Execution' set to 'Deferred', otherwise the PowerShell script is immediately executed. 

The problem I'm running into is that the property is always empty. This is 100% caused by the 'Deferred' execution, but I really need this to work. Any ideas?

Labels (1)
0 Kudos
1 Solution
GomochaInstall
Level 5

I figured this one out. Let's assume you have a PowerShell Custom Action you want to run in deferred execution. The PowerShell Custom Action is named 'Foobar'. In order to use this in PowerShell you have to do the following:

1. Set the property in a dialog, let's assume the property is named FOOBAR_PROPERTY

2. Create a custom action by richt clicking the Custom Actions ->  New Set Property

3. Name that newly added property, for example "MakePropertiesAvailableForFoobar", set the Property Name  exactly the same as your PowerShell CustomAction so in this case, Foobar.

4. Now in the Property Value field you fill in the properties that were filled in from the dialog between square brackets like this: [FOOBAR_PROPERTY] (multiple properties can be added by adding a semicolon [FOOBAR_PROPERTY1];[FOOBAR_PROPERTY2]; etc)

5. Set the Sequence to Install Exec Sequence 'After LaunchConditions'.

6. Now in your PowerShell Custom Action, set In-Script Execution to 'Deferred Execution' (in my case I used In System Context)

7. Set the Sequence to Install Exec Sequence 'After PublishProduct'

8. Now in your powershell you can do the following:

$customactiondata = get-property -name CustomActionData
$customactiondataarray = $customactiondata.Split(";")
$foobar = $customactiondataarray[0]
 
And when you have multiple you just increase the index of the $customactiondataarray.
 
If you have a semicolon in your property, like I had when entering a connection string, you can apparently add multiple properties using any character in between (so I chose ~) and then in PowerShell you do $customactiondata.Split("~"). 

View solution in original post

0 Kudos
2 Replies
Revenera_Ian
Revenera Moderator Revenera Moderator
Revenera Moderator

Hello @GomochaInstall,

Thank you for your post.

Since your PowerShell Custom Action is running in deferred execution, you cannot directly access most Windows Installer (MSI) properties. Most MSI properties are not directly accessible during deferred execution. Instead, you need to access your MSI property via a special MSI property named CustomActionData.

Here is a link to documentation about using the CustomActionData MSI property:

Accessing or Setting Windows Installer Properties Through Deferred, Commit, and Rollback Custom Actions

https://docs.revenera.com/installshield27helplib/helplibrary/AccessingProps-DeferredCAs.htm

Please give this suggestion a try. Does this work for you?

Please let us know if you have any questions or concerns. Thanks!

0 Kudos
GomochaInstall
Level 5

I figured this one out. Let's assume you have a PowerShell Custom Action you want to run in deferred execution. The PowerShell Custom Action is named 'Foobar'. In order to use this in PowerShell you have to do the following:

1. Set the property in a dialog, let's assume the property is named FOOBAR_PROPERTY

2. Create a custom action by richt clicking the Custom Actions ->  New Set Property

3. Name that newly added property, for example "MakePropertiesAvailableForFoobar", set the Property Name  exactly the same as your PowerShell CustomAction so in this case, Foobar.

4. Now in the Property Value field you fill in the properties that were filled in from the dialog between square brackets like this: [FOOBAR_PROPERTY] (multiple properties can be added by adding a semicolon [FOOBAR_PROPERTY1];[FOOBAR_PROPERTY2]; etc)

5. Set the Sequence to Install Exec Sequence 'After LaunchConditions'.

6. Now in your PowerShell Custom Action, set In-Script Execution to 'Deferred Execution' (in my case I used In System Context)

7. Set the Sequence to Install Exec Sequence 'After PublishProduct'

8. Now in your powershell you can do the following:

$customactiondata = get-property -name CustomActionData
$customactiondataarray = $customactiondata.Split(";")
$foobar = $customactiondataarray[0]
 
And when you have multiple you just increase the index of the $customactiondataarray.
 
If you have a semicolon in your property, like I had when entering a connection string, you can apparently add multiple properties using any character in between (so I chose ~) and then in PowerShell you do $customactiondata.Split("~"). 
0 Kudos