Reputation: 511
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.
Upvotes: 1
Views: 886
Reputation: 1886
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";
}
Upvotes: 2
Reputation: 20800
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.
Upvotes: 2