How to have conditional changes inside an MSI

Issue: You want to perform a change (copy a file, plug the registry, etc) but you want to test for

a condition before you apply it.

Solutions:

Method 1-Use Conditional Features: (Best solution)

-Go to the Installation Expert view

-In Project Definition click on Features

-Browse to where you want to create the new feature and click Add Condition button

-Add in your condition in the Condition field and click OK.

NOTE: In our example, we are using an environment variable. The "~=" means non Case-insensitive compare. (BTW: OS_LANG doesn't exist by default in Windows)

We could also test a property like this: MYPROP = “ABC”. This property can also be set by a System Search to test if a file or registry setting exists or not.

-To add a file for that condition, go into the files node and select the newly created feature.

-Now add the files that you need for that condition.

-You should be able to figure out the rest for registry entries, etc.

NOTE: You can also add features to an existing MSI or WSI using SetupCature by using the Add/Update Resources in Existing Installation option.




Method 2- Use Custom Actions in MSI script. Here you have many options but beware that none of them will be part of an MSI rollback. You can use:

-A DOS command for the simple stuff.

-A VBS script for more elaborate stuff (good for portability between MSI packagers)

-Another MSI package

-An EXE (ie. A SMS installer package)

-WiseScript


Since you don’t want these files to be left after they run you want to add them to your package as a resource.

-Place these files in the Project folder for your target package.

-In the target package:

Go to the MSI Script view:

-Select the Execute Deferred page

-Just before the CreateFolders action add a custom action that ends with From Installation

ie: Call VBScript From Installation

Execute Program From Installation

Install MSI From Installation

-Enter a name for your Custom Action (Anything, it's just a cute label)

-Browse to your file that is located in the Project folder for your target package

-Click Ok