Detecting repair, patch install, and patch uninstall for Windows Installer

A frequently asked question is how to detect whether a product installed using Windows Installer is being repaired, or a patch is being installed or — starting with Windows Installer 3.0 — uninstalled. The answer is detecting which properties are set.

When a product — or even a single feature or multiple features — is being repaired the REINSTALL property is set; however, understand that patching is the act of transforming the view of the original product and re-installing features that contain files to be patched. That means the REINSTALL property will also be set during patch install and uninstall scenarios.

When patching a product, the PATCH property is set to a single or — starting with Windows Installer 3.0 — semicolon-delimited list of patches (.msp files). If that property is set than you can condition your actions to run during patch installation scenarios. When a patch is being uninstalled you can check if the MsiPatchRemovalList property is defined. This contains a semicolon-delimited list of the patch codes being removed. You can also use the MSIPATCHREMOVE property — a single or semicolon-delimited list of patch codes or patches (.msp files), but the MsiPatchRemovalList property is recommended.

For more information about conditions in Windows Installer, read Using Properties in Conditional Statements in the Windows Installer SDK.