PDA

View Full Version : Wait till spooler is Started/Stopped



lmilesuk
01-14-2015, 06:51 AM
Hi,

I'm creating a Basic MSI project, on uninstall I need to delete some installed dll's, however to do this I need to start/stop the spooler, I can do this in install script using;

ServiceStopService("Spooler");
ServiceStartService("Spooler", "");

At present I have added a Delay(5); after each command before attempting to remove the files, however it can take longer or even be faster for the spooler to start on stop dependent on each users system, is there a way for me to check that the spooler has in fact been stopped or started before continuing execution of the script?

Many thanks in advance

TsungH
01-15-2015, 08:07 PM
Out of curiosity, why don't you use MSI built-in functionality ServiceControl Table (http://msdn.microsoft.com/en-us/library/aa371634(v=vs.85).aspx) to stop and start service?

Hysteresis
01-16-2015, 08:24 AM
I agree with TsungH. However if for some reason you can't do that you could use ServiceGetServiceState in a loop which delays say for 1 sec between iterations. After the delay check for the service stopped state. When its stopped you know its safe to proceed.

You might want to put an overall timeout on this though in case the service refuses to shutdown for some reason.