InstallShield Tips and Techniques

January 16, 2009

Conditionally install features via scripting

Filed under: InstallShield Scripting — shieldmaster @ 7:08 pm

 

 

 

I was recently dealing with an application install and wanted to selectively activate some features via scripting.  Turns out the application had three platforms and one of the platforms had four separate options. The typical method was to use the Custom Setup, but I wanted more flexibility.

 

Here was the situation, I created two screens that the user would be able to choose selections; the first was a Platform screen,

 

vision1

 

 

And then if Balance was chosen then they could pick components (one, none or all) from the four that were available.

vision2

 

 

What I wanted to achieve was to have InstallShield features created for the following:

  • CommonFiles – this contains all common files needed by application, regardless of the platform chosen
  • Stability – these files would be delivered if customer selected Stability as a platform
  • Balance – this was some core files for Vision that would be required when the platform Balance was selected.
  • Optionally, when the these specific components for Balance are selected:
    • Balance_Client – these files within this feature would be selected if the user checked the box “Client for Balance”
    • Balance_CacheMonitor – these files within this feature would be selected if the user checked the box “Cache Monitor”
    • Balance_SearchMonitor – these files within this feature would be selected if the user checked the box “Search Monitor”
    • Balance_AuditMonitor – these files within this feature would be selected if the user checked the box “Auditing”
  • Viewer – these files would be delivered if customer selected Viewer as a platform

 

 

With those dialogs and the features created, and components and files populated, how could I selectively activate the features based on user selection?

 

Here is how I accomplished it:

  1. On each feature that I wanted conditionally set, I first set the InstallLevel value to be 300 – which prevents the feature from being installed (assuming default INSTALLLEVEL property value of 100). 

       

 

  1. You will need to create a script that runs after the dialogs have been displayed and the user makes the selection.  Here is a snippet that I created:

 

// ******************************************************

// ** Obtain the value of the MSI Property associated

// ** with the Audit Checkbox

// ******************************************************

nBuffer = 256;   

MsiGetProperty (ISMSI_HANDLE, “VER_BAL_COMPONENT_AU”,

               szCS_Component_AU, nBuffer);

szBuffer = “ver–> Retrieved ‘%s’ value from the MSI Property “ +

“VER_BAL_COMPONENT_AU ‘ “;

Sprintf (szLogMessage, szBuffer, szCS_Component_AU);

ver_WriteLogFile (szLogMessage);

 

// ******************************************************

// ** If checkbox was checked, then set the corresponding

// ** MSI Property to be an ACTIVE switch

// ******************************************************

 

if (szCS_Component_AU  = “1”) then

   MsiSetProperty (ISMSI_HANDLE, “AUDIT_SWITCH”, “ACTIVE”);

   szBuffer = “ver–> Set ‘%s’ as value for the MSI Property “ +

               “’AUDIT_SWITCH’ “;

   Sprintf (szLogMessage, szBuffer, “ACTIVE”);

   ver_WriteLogFile (szLogMessage);

endif;  

  

I pulled the value of the MSI Property associated with the Balance Component “Auditing”.  If the value was “1” – then the user had checked the “Audit” box. All I had to do was then set the MSI Property “AUDIT_SWITCH” to have a value of “ACTIVE”.

 

Now this script is run by a Custom Action that is set to run after the dialogs have completed in the UI Sequence.  But because the UI Sequence does not run when executing silently – you need to have the Custom Action set to “Run Only Once” and have the CA also run in the Execute Sequence. 

 

  1. Finally, I created some Custom Actions that will set the MSI Property “ADDLOCAL” which is the property that lets the Windows Installer know what features are being installed.  These will be Type 51 – “New Set Property” and will only run in the Execute Sequence.  I will initialize the MSI Property “ADDLOCAL” with the features that are always required and then build the string, adding more features as necessary.  Here are some sample Custom Actions:
    1. Custom Action Name:  ISI_SetBaseFeatures

                                                               i.      Property Name: ADDLOCAL

                                                             ii.      Property Value:  CommonFiles

                                                            iii.      Execution Scheduling: Always Execute

                                                           iv.      Install Exec Sequence:  Schedule after AppSearch

                                                             v.      Install Exec Condition:  NOT Installed

  1.  
    1. Custom Action Name:  ISI_SetBalance

                                                               i.      Property Name: ADDLOCAL

                                                             ii.      Property Value:  [ADDLOCAL],Balance

                                                            iii.      Execution Scheduling: Always Execute

                                                           iv.      Install Exec Sequence:  Schedule after ISI_SetBaseFeatures

                                                             v.      Install Exec Condition:  BALANCE_SWITCH=”ACTIVE”

  1.  
    1. Custom Action Name:  ISI_SetAuditing

                                                               i.      Property Name: ADDLOCAL

                                                             ii.      Property Value:  [ADDLOCAL],Balance_AuditMonitor

                                                            iii.      Execution Scheduling: Always Execute

                                                           iv.      Install Exec Sequence:  Schedule after ISI_SetBalance

                                                             v.      Install Exec Condition:  AUDIT_SWITCH=”ACTIVE”

 

 

Basically, I took the MSI Property “ADDLOCAL” and initialized it to the features that I considered mandatory – in this case the feature “CommonFiles”.  

From this point on, each Custom Action would append another feature to the MSI Property when the condition was met. 

 

In the above examples, if the user chose the checkbox in the dialog “Auditing”, then after the script ran the MSI Property “AUDIT_SWITCH” was set to “ACTIVE”.  That triggers the condition in Custom Action “ISI_SetAuditing” so that the feature name “Balance_AuditMonitor” will be appended to the MSI Property “ADDLOCAL” (Note: the use of apostrophe in the value!).  Another feature has been activated.

 

 

Hope this sheds some light on how to make InstallShield work for you!

Advertisements

3 Comments »

  1. Thank you a lot.
    I know, this post is old, but it has helped me a lot, I had thank you.

    I have tried do that some times in past and I couldn’t anyway. Now, in this way you said, I could!!!

    I didn’t know this blog, I found by Google and now, I’ll follow, ’cause installshield has many things and some are hard to know!
    I hope to learn a bit more!

    😉

    Comment by Gabriel — September 8, 2010 @ 5:48 pm

  2. I’m not sure where you’re getting your information, but great topic.
    I needs to spend some time learning more or understanding more.

    Thanks for magnificent information I was looking for this information for my mission.

    Comment by torebka damska — April 16, 2013 @ 9:20 pm

    • Appreciate the feedback! I have been doing this almost 18 years – using InstallShield since version 3.0, reckon it’s called “experience”.

      ShieldMaster

      Comment by shieldmaster — April 16, 2013 @ 10:13 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: