8 out of 23 rated this helpful - Rate this topic

Examples of Conditional Statement Syntax

The following provides some common instances of conditional statements. For more information, see Conditional Statement Syntax.

Run action on removal.

For information, see Conditioning Actions to Run During Removal.

Run action only if the product has not been installed.

NOT Installed

Run action only if the product will be installed local. Do not run action on a reinstallation.

(&FeatureName=3) AND NOT(!FeatureName=3)

The term "&FeatureName=3" means the action is to install the feature local. The term "NOT(!FeatureName=3)" means the feature is not installed local.

Run action only if the feature will be uninstalled.

(&FeatureName=2) AND (!FeatureName=3)

This condition only checks for a transition of the feature from an installed state of local to the absent state.

Run action only if the component was installed local, but is transitioning out of state.

(?ComponentName=3) AND ($ComponentName=2 OR $ComponentName=4)

The term "?ComponetName=3" means the component is installed local. The term "$ComponentName=2" means that the action state on the component is Absent. The term "$ComponentName=4" means that the action state on the component is run from source. Note that an action state of advertise is not valid for a component.

Run action only on the reinstallation of a component.

?ComponentName=$ComponentName

Run action only when a particular patch is applied.

PATCH AND PATCH >< MEDIASRCPROPNAME

For more information, see the Remarks section on the PATCH property page.

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
More information, please!
Let me add my voice to the ones begging for clearer, more comprehensive documentation.  Ideally, it would be great to have something more line with the standard set by .NET Framework documentation, where complete sample code (including context) is provided and hyperlinks to pages explaining key concepts are included.
More examples
I would have hoped to have a lot more examples here.&nbsp; Like pretty much every commonly used combination and its meaning.
Example with environment variables and case insensitive string comparison
Here's an example of a condition on an environment variable. Environment variable EXAMPLE equals to "string" in a case insensitive way:

%EXAMPLE ~= "string"
...and a tip for testing non-trivial conditions, specially from Visual Studio: use Orca to open your MSI, edit the condition and validate the installer before using it
Need More Examples AND a FAQ
I agree with the other comments above. We (real developers) desperately need better documentation on common conditions.  I have been searching now for 3 or 4 hours trying to determine the syntax of a condition that will cause a custom action to be performed when installing, but NOT performed when uninstalling. Surely that is a common thing! Where are the FAQ's for Windows Installer?
Definitely more examples.
I agree, more examples... especially of the most commonly used conditions. Not all programmers are EXPERTS at deploy/install creation. It appears that is the one area that is completely ignored by Microsoft as well as others. It's ignored, because you only provide the syntax and one or two simplistic examples. It's great to have all these wonderful tools, like VS2008 or VS2010... but just giving the syntax of each command/process is like giving a french person a book on how to spell english words, and then saying, "This is all you need to know about how to speak english.".