BOOL WINAPI ControlService(
_In_ SC_HANDLE hService,
_In_ DWORD dwControl,
_Out_ LPSERVICE_STATUS lpServiceStatus
);
Control code | Meaning |
---|---|
| Notifies a paused service that it should resume. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. (恢复服务,需要SERVICE_PAUSE_CONTINUE权限) |
| Notifies a service that it should report its current status information to the service control manager. The hService handle must have the SERVICE_INTERROGATE access right. Note that this control is not generally useful as the SCM is aware of the current state of the service. (向SCM报告服务的当前状态信息,需要有SERVICE_INTERROGATE权限) |
| Notifies a network service that there is a new component for binding. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead. (网络绑定相关,已废弃) |
| Notifies a network service that one of its bindings has been disabled. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead. (网络绑定相关,已废弃) |
| Notifies a network service that a disabled binding has been enabled. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead. (网络绑定相关,已废弃) |
| Notifies a network service that a component for binding has been removed. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead. (网络绑定相关,已废弃) |
| Notifies a service that its startup parameters have changed. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. (服务启动参数已经改变,需要有SERVICE_PAUSE_CONTINUE权限) |
| Notifies a service that it should pause. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. (暂停服务,需要有SERVICE_PAUSE_CONTINUE权限) |
| Notifies a service that it should stop. The hService handle must have the SERVICE_STOP access right. After sending the stop request to a service, you should not send other controls to the service. (停止服务,需要有SERVICE_STOP权限) |
Return code | Description |
---|---|
| The handle does not have the required access right. |
| The service cannot be stopped because other running services are dependent on it. |
| The specified handle was not obtained using or , or the handle is no longer valid. |
| The requested control code is undefined. |
| The requested control code is not valid, or it is unacceptable to the service. |
| The requested control code cannot be sent to the service because the state of the service is SERVICE_STOPPED, SERVICE_START_PENDING, or SERVICE_STOP_PENDING. |
| The service has not been started. |
| The process for the service was started, but it did not call , or the thread that called StartServiceCtrlDispatcher may be blocked in a control handler function. |
| The system is shutting down. |
To stop and start a service requires a security descriptor that allows you to do so. The default security descriptor allows the , and members of the Administrators and Power Users groups to stop and start services. To change the security descriptor of a service, see .
The function returns a structure whose dwCurrentState and dwControlsAccepted members indicate the current state and controls accepted by a running service. All running services accept the SERVICE_CONTROL_INTERROGATE control code by default. Drivers do not accept control codes other than SERVICE_CONTROL_STOP and SERVICE_CONTROL_INTERROGATE. Each service specifies the other control codes that it accepts when it calls the function to report its status. A service should always accept these codes when it is running, no matter what it is doing.
The following table shows the action of the SCM in each of the possible service states.
Service state | Stop | Other controls |
---|---|---|
STOPPED | (c) | (c) |
STOP_PENDING | (b) | (b) |
START_PENDING | (a) | (b) |
RUNNING | (a) | (a) |
CONTINUE_PENDING | (a) | (a) |
PAUSE_PENDING | (a) | (a) |
PAUSED | (a) | (a) |
- (a)
-
If the service accepts this control code, send the request to the service; otherwise, ControlService returns zero and returns ERROR_INVALID_SERVICE_CONTROL.
(b) -
The service is not in a state in which a control can be sent to it, so ControlService returns zero and returns ERROR_SERVICE_CANNOT_ACCEPT_CTRL.
(c) -
The service is not active, so ControlService returns zero and returns ERROR_SERVICE_NOT_ACTIVE.
本文链接: