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'
/>