PDA

View Full Version : Removing Services?



stevendm
05-05-2004, 09:25 AM
I am using DevStudio 9 with an InstallScript MSI Project. I have added a service using the ServiceAddService command.

At uninstall time, in a FeaturesUninstalled event handler I use the ServicesStopService and ServicesRemoveServices command to stop and remove the service. If I look at the Services MMC I see that the service still exists but is marked as disabled. I need to delete the directory that contains the service executable. Even when I get to the OnEnd event the service still exists, but is marked as disabled.

Once I dismiss the final screen that indicates that the uninstallation is complete the Services MMC indicates that the service is gone. But the installer has exited and I cannot run any code.

What should I do. I do not want to force a reboot, I shouldn't have to.

TIA

Steven

muk_chak
05-19-2005, 04:01 PM
Hi steven, I was facing the same issue for days and finally i figured it out.
There should be a file called sc.exe in the system32 folder of xp machines. Add that file to your SUPPORTDIR (support directory).

Then, include the following code in the OnUpdateUIBefore event.

Enable(HOURGLASS);
szMessage = "please wait ...";
SdShowMsg(szMessage,TRUE);

LaunchAppAndWait("net.exe"," stop <Servicename>",",WAIT);
LaunchAppAndWait(SUPPORTDIR ^ "sc.exe"," delete <Servicename>",WAIT);

Delay(5);
Disable(HOURGLASS);
SdShowMsg (szMessage, FALSE);

The above code will execute before updatestarts and remove the service. Then the update process will update all the service files and then in the OnUpdateUiAfter event, include the following code to install your new service:

LaunchAppAndWait( TARGETDIR ^ "installutil.exe", "<ServiceName.exe>", LAAW_OPTION_WAIT)

Cheers! :)