How to detect or stop a process
The following article uses options that are available starting with the Professional edition and project type.
When updating an installation, it is recommended you stop the installed application before overwriting its files. Usually, this is managed automatically by Windows Installer through the "FilesInUse" and "MsiRMFilesInUse" dialogs, but you can close your application whenever you want to, through a custom action.
1. Detect if a process is running
You can detect if a process is running by using a "Detect Process" predefined custom action. This custom action can be added at any point in the installation. If you want it to run at the beginning of the install process, you can schedule it before "Wizard Dialogs Stage" -> "Searches". It should also be dragged before "Install Execution Stage" -> "Searches" while the SHIFT key is pressed to make sure that it runs even if there is no UI.
Since it uses installer properties, this custom action can only run as Immediate.
After adding the custom action, in its Custom Action Properties page the Process Name field should be set to the name of the process you want to detect. When the custom action runs, it will set the AI_PROCESS_STATE property to one of these values:
- Running - the process is running
- Stopped - the process is stopped (no process with the name you specified is currently running)
The AI_PROCESS_STATE property can be used as a Custom Launch Condition in order to stop the installation if a process is running.
2. Stop a process
In order to stop a running process, you can use a "Terminate Process" predefined custom action. If you want the custom action to run in the beginning of the installation, you can schedule it before "Wizard Dialogs Stage" -> "Searches". It should also be dragged before "Install Execution Stage" -> "Searches" while the SHIFT key is pressed to make sure it runs even if there is no UI. In this case the custom action should use the "Execute only once if present in both sequence tables" option in the Custom Action Properties page.
After adding the custom action, in its "Custom Action Properties" page, the Process Name field should be set to the name of the process you want to stop.
Stopping a process may require Administrator privileges. In this case, the custom action should be configured to run as Deferred with no impersonation. Since deferred custom actions can only run after "Preparing" action group, your custom action should be scheduled accordingly.