12.9. Controlling Services

Generally you control a service using the Services applet in the Control Panel. This service allows you to start, stop, pause, or resume any service. There are some cases, however, in which it is useful to be able to control a service either from a separate program or from another service. The ControlService and StartService functions allow you to control services in your code.

ControlServiceSends a control constant to the specified service
BOOL ControlService(
   SC_HANDLE service,
   DWORD control,
   LPSERVICE_STATUS status)
serviceA handle to the service
controlControl constant telling the service what to do
statusA pointer to a SERVICE_STATUS structure
Returns TRUE on success

The ControlService function accepts a handle ...

Get Win32 System Services: The Heart of Windows® 98 and Windows® 2000 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.