Stopping A Service In WIX And Starting When Install Is Complete

TimWagaman picture TimWagaman · Jun 13, 2012 · Viewed 7.7k times · Source

I'm using WiX 3.5 to create an installer that installs a Windows Service and copies DLL's to the bin directory of a third party app. The third party app has a series of Windows Services also that will need stopped before the DLL's get copied and started after the install is complete. What would I need to do to accomplish this. I have looked for examples, but can only find how to start the service that I'm installing.

***On a side note, the service that I am installing needs to run under a specific user account. I see how to define the Service Account/Password in WIX, but I'm hesitant to use that because it stores the password unencrypted in XML, and I have security concerns with that.

Answer

Christopher B. Adkins picture Christopher B. Adkins · Jun 14, 2012

First off, to stop a service you need to use the ServiceControl element.

<ServiceControl Id="serviceName" Name="actualServiceName" Stop="both" Start="both" Wait ="yes" />

To answer your side not, you can have the username and password be properties that the user sends to the MSI, or that the user enters from the GUI.

<ServiceInstall Id="serviceName" Name="shortName" DisplayName="longName" Type="ownProcess" Start="auto" ErrorControl="normal" Account="[USER]" Password="[USERPWD]" Description="description" />
<Property Id="USER" Value="defaultValue" />
<Property Id="USERPWD" Value="defaultValue" Hidden="yes" />

Of course, the default value is not needed, and not really recommended, but I still put it in there.