MSI: Start service unless user choses to reboot machine
I am working on MSI installer which installs and starts the service. It may or may not replace files in use. When it does, there is a prompt to reboot machine at the end of install.
Service runs lengthy initialization on the first startup, which is undesirable to interrupt by shutdown. What I am trying to do is to prevent service from starting until it is known that setup completed, and there will not be a reboot, e.g.: reboot not needed or user selected to postpone reboot.
开发者_Go百科Bootstrapper is not an option, all must be implemented inside an MSI
Can somebody advise me, what's the best way to do this?
I'm going to give a pragmatic although not perfect answer.... Windows Installer doesn't really have any way to support this so just intentionally request a reboot and don't have a ServiceControl element. Just set the ServiceInstall to Auto and let the reboot take care of the rest.
I know, I usually try to avoid reboots also but if you are frequently likely to need one anyways well it just makes your whole story simpler.
The only other thing I can really think of is to expose an RPC mechansim in your service ( wcf end point for example ) and have your long running process only take place on either the second start of the service or when that rpc is invoked the first time. Then have a custom action at the end of the installer call the rpc if a reboot is not required.
I just can't think of any way to do it natively in MSI.
精彩评论