To adhere to the Windows Installer "Best Practices," all changes that are made to a system are in a "deferred" action.
A deferred execution custom action must be scheduled in the execute sequence table within the section that performs script generation.
Deferred execution custom actions must come after "InstallInitialize" and come before "InstallFinalize" in the action sequence.
You can only call the following functions in this type of action:
- MsiGetProperty
- MsiFormatRecord
- MsiGetMode
- MsiGetLanguage
- MsiProcessMessage
Only the following limited set of properties are always accessible to custom actions during script execution ( (i.e. deferred custom action).
! - Installed state
& - Action state
? - Installed state
$ - Action state
1 - Advertised feature. This state is not available for components.
2 - Feature or component is not present.
3 - Installed local.
4 - Feature or component run from the source.
- http://msdn.microsoft.com/en-us/library/aa368012(VS.85).aspx
- http://www.joyofsetup.com/2008/04/09/feature-states-in-component-conditions/
Add a condition on the action so it's only triggered during installation, not uninstallation. Action run only during Install
NOT Installed AND NOT PATCH
Action runs during Install and repair
NOT REMOVE
Run on initial installation only:
NOT Installed
Run on initial install or when repair is selected.
NOT Installed OR MaintenanceMode="Modify"
Finally, to only run an action during uninstall use the following condition:
REMOVE
Install:
&feature=3
Reinstall, upgrade:
!feature=3 AND &feature<>2
Action run only during Install Condition: NOT Installed AND NOT PATCH
Action only runs during removal of MSI Condition: REMOVE
Action runs during Install and repair Condition: NOT REMOVE
Action runs during Install and remove Condition: There must be no condition
Action calls EXE installed by MSI Condition:NOT Installed AND NOT PATCH
Run on initial installation only: NOT Installed
Run on initial install or when repair is selected. NOT Installed OR MaintenanceMode="Modify"
Run when being uninstalled from command line or add / remove menu. REMOVE~="All" OR MaintenanceMode="Remove"
It's worth mentioning that the documentation for Windows Installer's
Session.FeatureRequestState
mentionsmsiInstallStateDefault=5
, which corresponds toINSTALLSTATE_DEFAULT
whichMsiGetFeatureState
might return.I found by reading the installer logs that MSI would record a feature as REINSTALL when doing a repair.
I am using
&Feature=3 or &Feature=5
to run a custom action when installing or repairing a product.