开发者

WiX uninstaller: restart service if present

Part of our app involves registering a plug-in to a third-party product. While the third-party service is running, it has our DLL loaded, so the files on disk are locked.

So when we uninstall our product, we need to begin by stopping the third-party service, and then restart it when we're done with the uninstall. (We also do the same stop/restart thing at install time, because if this is an upgrade, then the existing files are again locked.)

WiX has a command that handles the happy path, no problem:

<ServiceControl Id="SomeUniqueId" Name="NameOfTheirService"
                Start="both" Stop="both"/>

I.e., stop the service at the beginning of both install and uninstall, and restart it at the end of both install and uninstall. So far so good.

The problem comes if the end-user uninstalls the third-party app first, and then tries to uninstall our app. Our app won't work with the third-party service, but if the user wants to uninstall them both, there's nothing to force them to do it in a particular order. However, if the third-party service is no longer installed, then our uninstaller:

  1. Tries to stop the third-party service, fails because the service no longer exists, decides the failure isn't important, and continues.
  2. Uninstalls our product.
  3. Tries to restart the third-party service, fails because the service no longer exists, decides this failure is important, and brings up an error dialog saying, "Service 'NameOfTheirService' (NameOfTheirService) failed to start. Verify that you have sufficient privileges to start system services." (Retry / Cancel)
  4. If the user clicks Retry, goto 3.
  5. If the user clicks Cancel, roll back, and un-uninstall.

In other words, WiX's error handling is wrong. Stopping a service should be failure-tolerant, and it is. Starting a service after install can be failure-intolerant; that's fine: fail my install if the service won't start. But starting a service after uninsta开发者_运维知识库ll should be failure-tolerant, and it is not.

How can I restart a service after uninstall, without failing the uninstall if that service no longer exists?


If you add the Wait attribute to the SeviceControl element and set it to no then as well as "Retry" and "Cancel" you'll also get an "Ignore" button that users can click to continue the Install/Uninstall without having started/stopped the service.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜