The Windows Installer provides a feature tree control that makes it easy for users to choose which features to install and uninstall. However, that control is only displayed when the install is executed with full UI. Fortunately, there are three options to control feature states even when not displaying the UI. The first two options are preferred over the third but require the MSI's features are designed to be controlled.
Option 1: INSTALLLEVEL
The first option is to organize features into ever-increasing tiers using the
Feature/@Level. Then the INSTALLLEVEL property can be provided on the command-line to control which tier is installed. For example, consider the following five features organized in three tiers.
<Feature Id="FeatureTier1" Level="1" /> <Feature Id="FeatureTier2a" Level="2" /> <Feature Id="FeatureTier2b" Level="2" /> <Feature Id="FeatureTier3a" Level="3" /> <Feature Id="FeatureTier3b" Level="3" />
By default, the
1 and only
FeatureTier1 would be installed. However, if the
INSTALLLEVEL would be provided on the command-linelike so:
msiexec /i your.msi INSTALLLEVEL=2
FeatureTier2b features would be installed. To install everything
INSTALLLEVEL would need to be set to
3 or higher. This is a very simple solution but often finer control of features is required.
Option 2: Feature Condition
The most flexible option with fewest side effects is to use custom properties in conditions to control the install level of a features. Features can be enabled or disabled by default.
Feature enabled by default, use a property to disable it:
<Feature Id="FeatureA"> <Condition Level="0">DISABLE_FEATUREA</Condition>
Feature disabled by default, use a property to enable it:
<Feature Id="FeatureB" Level="0"> <Condition Level="1">ENABLE_FEATUREB</Condition>
The following command-line toggles both of the features as described above:
msiexec /i your.msi DISABLE_FEATUREA=1 ENABLE_FEATUREB=1
Note: as written, the value of the properties does not matter. Any non-empty string value will evaluate the conditions to true.
Option 3: ADDLOCAL, et al
If the MSI packages do not and cannot be updated to use feature conditions, the Windows Installer provides several properties to directly control the install state of the features. The following are the most useful listed in order of precedence:
ADDLOCAL- list of features to install
REMOVE- list of features to uninstall
ADDDEFAULT- list of features to set to their default state
REINSTALL- list of features to repair
You can provide the list on the command-line like so:
msiexec /i your.msi ADDLOCAL=FeatureA1;FeatureB REMOVE=FeatureC ADDDEFAULT=FeatureD REINSTALL=FeatureE;FeatureF
You can also use the keyword
ALL to indicate all features. For example the following installs all of the features in the MSI package:
msiexec /i your.msi ADDLOCAL=ALL
There are two important things to keep in mind when using these properties. First, the properties lower in the list trump the items higher in the list. Thus in the following command line all of the features would be set to their default state:
msiexec /i your.msi ADDDEFAULT=ALL ADDLOCAL=FeatureA REMOVE=FeatureB
The order of the properties on the command-line is irrelevant. Because
ADDEFAULT is later in the original list, it trumps
Second, the names of features are case sensitive and must match the
Feature/@Id from the authoring. For example, "FeatureA" is different from "featureA" and "Featurea".