davincicode
Posts: 7
Joined: Wed Apr 13, 2005 1:49 pm

how do you stop a windows service early in the uninstall?

My product is a specialized Windows service.
It installs NOT with the normal Windows service stuff, but by running it with command line options.
And it uninstalls also with command line options.
In the install I run a VB script (.vbs) file after installing it to start it.
And at uninstall time, I run a different VB script file that stops it.

So far everything works well. On install the service starts like a champ. However, I am getting some issues on uninstall:

Image

When I uninstall my application, I am getting funny dialogs like the above if my service is still running. I cannot determine how to stop my service at the very beginning of uninstall. I added a message box to my "stopservice.vbs" file and noticed that this message box does not pop up until well after the above warning dialog.

I tried to add a call to my stop service .vbs file earlier, but the Advanced Installer 2.51 does not appear to let you run external files except at certain places late in the install/uninstall. And if I do not stop my service early in the uninstall, AI/MSI gives me the dialog like the above. If I hit "ignore" my uninstall works just fine. However I would very very much like not to get this dialog.

This is my stop service VB script. It would be great if this was a built-in method that one could call anywhere.

Code: Select all

strComputer = "."

Dim objWMIService
Dim colServiceList
Dim objService

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='RMI CONFIG Agent'")

For each objService in colServiceList
    errReturn = objService.StopService()
Next
Any ideas?

Thanks,
Davinci Code
UdreaMihai
Posts: 90
Joined: Wed Mar 23, 2005 8:13 am

Hello Michael,

Windows Installer verifies the components that will be removed when the uninstall process begins ("Remove" button is pressed). You can stop your service (if it is running) anytime after "CostFinalize", not only on uninstall.

You may also try to use your program as a regular service.

Best,
Mihai
Udrea Mihai
Advanced Installer Team
http://www.advancedinstaller.com
davincicode
Posts: 7
Joined: Wed Apr 13, 2005 1:49 pm

UdreaMihai wrote:Hello Michael,

Windows Installer verifies the components that will be removed when the uninstall process begins ("Remove" button is pressed). You can stop your service (if it is running) anytime after "CostFinalize", not only on uninstall.

You may also try to use your program as a regular service.

Best,
Mihai
Thank you for your rapid response. I made the changes and attached a call to my VB script to the "MigrateFeatureStates" sequence point. If that is the right term. So far, it looks really good. No "bad" dialogs popping up during the uninstall. I appreciate your quick help.

As for making the program into a more Windows-like Windows service... well... that is a feat of bravery best left for another day! :-)

Return to “Common Problems”