Question

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.

  1. 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]
  2. 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 &amp;&amp; net start AppServerSvc'
        Return='asyncWait'
        Execute='deferred'
    />
Was it helpful?

Solution

If you schedule the upgrade MSI during the transaction, for example use:

  • MajorUpgrade/@Schedule='afterInstallInitialize' or
  • MajorUpgrade/@Schedule='afterInstallExecute' or
  • MajorUpgrade/@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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top