Redigera

Dela via


Service Control Requests

To send control requests to a running service, a service control program uses the ControlService function. This function specifies a control value that is passed to the HandlerEx function of the specified service. This control value can be a user-defined code, or it can be one of the standard codes that enable the calling program to perform the following actions:

  • Stop a service (SERVICE_CONTROL_STOP).
  • Pause a service (SERVICE_CONTROL_PAUSE).
  • Resume executing a paused service (SERVICE_CONTROL_CONTINUE).
  • Retrieve updated status information from a service (SERVICE_CONTROL_INTERROGATE).

Each service specifies the control values that it will accept and process. To determine which of the standard control values are accepted by a service, use the QueryServiceStatusEx function or specify the SERVICE_CONTROL_INTERROGATE control value in a call to the ControlService function. The dwControlsAccepted member of the SERVICE_STATUS structure returned by these functions indicates whether the service can be stopped, paused, or resumed. All services accept the SERVICE_CONTROL_INTERROGATE control value.

The QueryServiceStatusEx function reports the most recent status for a specified service, but does not get an updated status from the service itself. Using the SERVICE_CONTROL_INTERROGATE control value in a call to ControlService ensures that the status information returned is current.

Controlling a Service Using SC