Platform SDK: DLLs, Processes, and Threads

SetServiceStatus

The SetServiceStatus function updates the service control manager's status information for the calling service.

BOOL SetServiceStatus(
  SERVICE_STATUS_HANDLE hServiceStatus, // service status handle
  LPSERVICE_STATUS lpServiceStatus      // status buffer
);

Parameters

hServiceStatus
[in] Handle to the status information structure for the current service. This handle is returned by the RegisterServiceCtrlHandler function.
lpServiceStatus
[in] Pointer to the SERVICE_STATUS structure the contains the latest status information for the calling service.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

The following error codes can be set by the service control manager. Other error codes can be set by the registry functions that are called by the service control manager.

Error code Meaning
ERROR_INVALID_HANDLE The specified handle is invalid.
ERROR_INVALID_DATA The specified service status structure is invalid.

Remarks

A ServiceMain function first calls the RegisterServiceCtrlHandler function to get the service's SERVICE_STATUS_HANDLE. Then it immediately calls the SetServiceStatus function to notify the service control manager of its SERVICE_START_PENDING status.

When a service receives a control request, the service's Handler function must call SetServiceStatus, even if the service's status did not change. A service can also use this function at any time and by any thread of the service to notify the service control manager of status changes. Examples of such unsolicited status updates include:

A service can call this function only after it has called RegisterServiceCtrlHandler to get a service status handle.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Header: Declared in Winsvc.h; include Windows.h.
  Library: Use Advapi32.lib.

See Also

Services Overview, Service Functions, Handler, RegisterServiceCtrlHandler, SERVICE_STATUS, ServiceMain, SetServiceBits