Is it possible to restart a service if setup MSI is cancelled by the user?
There is two scenarios where the MSI has to restart the service.
- Stop and update the old service files and then start the service. If service fails to start, replace back the old files and restart the service. [This part is done with rollback]
- Restart the service if MSI is cancelled intentionally during setup process.
I have a solution that I can call a CustomAction
on cancel and used CMD.EXE to restart a service, but I don't like it. Please suggest any other solution like by using RestartResource
or ResourceManager
Code:
<InstallExecuteSequence >
<RemoveExistingProducts
After="InstallInitialize"/>
<Custom Action="RenameFileOnCancel" OnExit="cancel">1</Custom>
</InstallExecuteSequence>
<CustomAction
Id='RestartService'
Directory='TARGETDIR'
ExeCommand='[SystemFolder]cmd.exe net stop AppServerSvc && net start AppServerSvc'
Return='asyncWait'
Execute='deferred'
/>
If you schedule the upgrade MSI during the transaction, for example use:
MajorUpgrade/@Schedule='afterInstallInitialize'
orMajorUpgrade/@Schedule='afterInstallExecute'
orMajorUpgrade/@Schedule='afterInstallExecuteAgain'
and use the
ServiceControl
element to start/stop/restart the service then the Windows Installer will do all the work for you.This is by far the most recommended way to accomplish your goal.