Search code examples
servicewixcustom-action

Wix: Can execute a custom action before InstallValidate?


During uninstall progress, the installer displays below message:

"The setup must update files or services that cannot be updated while the system is running. If you choose to continue, a reboot will be required to complete the setup."

I think it's caused by the installed service is still running while uninstalling. So, I try to write a custom action to stop it. But, it seems not work.

If I set the action as Execute='deferred' Impersonate='no', it only allows me to put action between InstallInitialize and InstallFinalize, so I have to set it as "immediate".

<CustomAction BinaryKey='CustomActions' Id='StopService' DllEntry='StopService' Execute='immediate' />

<Custom Action="StopService" Before="InstallValidate">REMOVE="ALL"</Custom>

Also note that, I have to use custom action to install service manually instead of using Wix by some reasons. That's why I'm trying to remove it manually.


Solution

  • You cannot run an elevated custom action before InstallInitialize. If you were to install the service normally, MSI would take care of stopping the service for you and not show the in-use message.