[Q] Why does ControlService(SERVICE_CONTROL_STOP) return ERROR_IO_PENDING?

I have a little device loader app that I wrote myself that works great under
NT 4.0. It has never experienced an ERROR_IO_PENDING result from the
Service Manager under NT 4.0.

Under Windows 2000, the app still loads and starts drivers just fine
(although ERROR_IO_PENDING is also returned in this case), but issuing a
SERVICE_CONTROL_STOP causes ERROR_IO_PENDING to be returned – and then
nothing happens. The driver is never unloaded – although it is apparently
purged after a reboot.

Under NT 4.0, the driver’s Unload() routine would be called immediately upon
SERVICE_CONTROL_STOP being issuued, apparently synchronously.

Why this change in Windows 2000? In any case, as a client of the Service
Manager API, what am I supposed to do when I receive ERROR_IO_PENDING? Am I
supposed to wait on the service handle or something? Or, do I keep calling
QueryServiceState() to see why my stop request takes effect? These would
all be nice except, as I said, my stop commands never seem to take effect
anyhow.

There is one detail that concerns me. In the loader app, I open, stop and
close a driver service with a quick succession of Service Manager calls,
approximately as follows.

hMyDriver = OpenService( …, “MyServiceName”, … );

ControlService(hMyDriver, SERVICE_CONTROL_STOP);

CloseServiceHandler(hMyDriver);

Am I closing ‘hMyDriver’ too soon?

Thanks for any insights.

  • Matt