This is not recommended because it prevents the user from uninstalling the application. Even if the service is running, the uninstall can still be performed. The only inconvenience is that it would need a reboot to finish.
However, if you really want to prevent the uninstall, you can try this approach:
- make sure that your Detect Service
custom action is scheduled before InstallUISequence -> LaunchConditions standard action
(for example you can move it after AppSearch action)
- in the custom action properties pane set the service name in Action Data
- condition this action to run only during uninstall
- while SHIFT key is pressed drag it over InstallExecuteSequence -> AppSearch standard action so it also runs for silent installations
- in the action properties pane select Execute only once if present in both sequence tables
- when the custom action will be executed, the AI_SERVICE_STATE property will be set to Started
or Not Found
, depending on the service
- you can use the AI_SERVICE_STATE property as a custom launch condition
, for example:
- Code: Select all
AI_SERVICE_STATE <> "Started"
An uninstall cannot be performed until service <your service> is stopped.
Launch conditions are evaluated only during install by default, so you need to remove the condition for LaunchConditions action in both InstallUISequence and InstallExecuteSequence. For this you can simply show the LaunchConditions action in Custom Actions page, select the action and change its condition.