1

In the Wix installer, how do I make it so that the installer will only start a service if it was started/running and stopped by the installer during the update process?

EDIT To clarify, I have a service which is a component of my installer which is installed based upon certain parameters. The problem I am having is that if I set , then the service will be started regardless of its state prior to the installation. I would like it so that the service would only start if it was running prior to the running of my wix installer.

dingdangdowney
  • 501
  • 1
  • 8
  • 22
  • you can check condition if installer is installing or updating. refer table in answer from the link for actual conditions. http://stackoverflow.com/a/17608049/3959541 – Chaitanya Gadkari Jan 28 '16 at 13:12

2 Answers2

2

I think you'd need to do this with custom action code. I know of no built-in functionality in WiX or Windows Installer that can keep track of whether a service was running at the start of the install. So you'd need to interrogate the service state with a custom action and set a property accordingly. At the end of the install (around where the StartServices standard action would be) you can have a custom action to restart that service. I wouldn't use a condition on the ServiceControl action to start the service because that will affect all services you want to start.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
2

As suggested above you will need to run custom action using c# for example:

ServiceController sc = new ServiceController(SERVICENAME);

switch (sc.Status)
{
    case ServiceControllerStatus.Running:
      return "Running";
    case ServiceControllerStatus.Stopped:
      return "Stopped";
    case ServiceControllerStatus.Paused:
      return "Paused";
    case ServiceControllerStatus.StopPending:
      return "Stopping";
    case ServiceControllerStatus.StartPending:
      return "Starting";
    default:
      return "Status Changing";
}
Arkady Sitnitsky
  • 1,846
  • 11
  • 22
  • Thank you - This is along the lines of what I ended up doing. I was hoping to get away with not using custom actions, but I am checking for which of the services are running prior to the stopservices event, and setting a property in the WiX session which I check later in a separate custom action to start them up again. – dingdangdowney Jan 29 '16 at 15:19