PDA

View Full Version : Stopping a service that is already installed



DLee65
10-17-2013, 05:37 AM
I have a basic msi package where I need to schedule a service to stop when the install starts. Note that I am not creating this service with this package, I am expecting that the service already exists. I will do a check to see if it exists. This component to which the service will be tied will not execute unless the service exists.

In my ServiceControl Table I created a record gave it the name of the service on the local machine, which is the instance name of our installed database MSSQL$INSTANCENAME Event Flag is set to 2, no arguments, Wait is set to 0, and I have it set to a component that is installing. However, the service does not stop and so it causes errors in the install.

I basically have a requirement to make a copy of the mdf file before copying any files. The company wants to be extra cautious when it comes to consumer data that it does not get overwritten in the installation process. So this is the end goal. In order to copy the file use the MoveFile table I need to stop the service.

Note that I have properly setup the components that include the mdf files to never overwrite the files, however, the company still wants to include this extra step.

So,what am I missing? I see the event firing off for stop services, but I do not see my service being stopped. Am I not including the correct service name? I am correct that it should be the service name and not the display name for the service that I include in the Name field?

BTW, there is nothing in validation that indicates any problems in my settings either.

DLee65
10-17-2013, 05:52 AM
Here is part of my MSI Log and I think I now know what is wrong.

MSI (s) (F0:40) [17:07:27:951]: Executing op: ServiceControl(,Name=MSSQL$AMAZINGCHARTS,Action=2,Wait=0,)
StopServices: Service: SQL Server (AMAZINGCHARTS)
MSI (s) (F0:40) [17:07:27:966]: Executing op: ActionStart(Name=RemoveODBC,Description=Removing ODBC components,)

I need to insert the wait for the service to stop.

rguggisberg
10-17-2013, 05:58 AM
Some things to try:
1. Perhaps it is a permissions issue. Have you tried 'Run as administrator' (assuming recent OS)?
2. Log the install and view log
3. Try stopping via a CA that launches a CMD window that executes SC STOP YourServiceName (See SC /? from CMD prompt)

DLee65
10-18-2013, 01:29 PM
The service was attempting to stop. However, I did not set the bit to wait for the service to complete the action. Of course it takes a few seconds for Windows to stop a service, and so if I just blow through it the other processes will attempt to run while the service is still attempting to shut down, and as a result the file is still locked. :)

With the wait bit set, the setup pauses until it completes. The down side ... if it fails to stop the setup will fail. But I guess that is the price we pay if we want to guarantee that the data has been backed up. Customer support has restored many client databases with this process in the past. ;)

Christopher Painter
10-19-2013, 09:45 PM
FWIW the service control functionality is pretty easy to rewrite and get full control of the behavior. :)