From: Alex Blekhman [alex@olivesoftware.com]


Hello,

Recently I came across a problem of stopping NT service from my
installation. As you probably know, even most recent product of
InstallShield - DevStudio 9 - has rather pathetic support for NT
services management. Look, for example, for KB article: Q107546 - "PRB:
ServiceStopService Function Stops an NT Service But Returns Failure
(<ISERR_SUCCESS)". Moreover, according to their isrt source (file:
"%ProgramFiles%\InstallShield\DevStudio 9\Script\isrt\src\Service.rul")
ServiceStopService function leaks service handle.

So, I end up with function that
	a) doesn't work
	b) leaks resources
	c) even in ideal case will not be able to stop service if it has
dependant services
	d) unnecessary tries to open SCM with SC_MANAGER_ALL_ACCESS
access rights while lesser rights are sufficient
	e) unnecessary tries to open the service with SERVICE_ALL_ACCESS
access rights while lesser rights are sufficient.

Summing it all up I came to conclusion that I need to stop a service by
myself. I went to MSDN library to figure how to do that. There is
"Stopping a Service" article in Platform SDK that explains how to stop
NT service correctly.

I had two choices:
	1. To make external EXE/DLL and use it from InstallScript
	2. To try to implement PSDK sample in InstallScript

I chose second option. It has its drawbacks (like absence of __finally
clause, for example). However, it has major advantage (at least for me)
to be independent from external programs/builds/projects.

The attached code is direct port of example shown in "Stopping a
Service" article in Platform SDK. I tested this code under DevStudio 9
SP1, OS: Windows 2000 SP4.

I hope this sample will help to somebody and will save a couple of
precious hairs on his head. Any corrections, notes and bug reports are
welcome.

Alex

