网站首页  词典首页

请输入您要查询的函数:

 

术语 controlserviceex
释义 ControlServiceEx
语法:
C++
BOOL WINAPI ControlServiceEx(
__in SC_HANDLE hService,
__in DWORD dwControl,
__in DWORD dwInfoLevel,
__inout PVOID pControlParams
);
ControlServiceEx功能
发送一个控制码服务。
参数
hService [in]
句柄的服务。这种处理是由OpenService或CreateService函数返回。在此访问权限处理取决于dwControl代码所需的要求。
dwControl [in]
此参数可以是下面的控制代码之一。
控制codeMeaning
SERVICE_CONTROL_CONTINUE
0x00000003Notifies已暂停服务,它应该恢复。该hService处理必须有SERVICE_PAUSE_CONTINUE访问权限。
SERVICE_CONTROL_INTERROGATE
0x00000004Notifies服务,它应报告其当前的状态信息服务控制管理器。该hService处理必须有SERVICE_INTERROGATE访问权限。
请注意,此控制不是一般的供应链管理有用的是对服务的当前状态认识。
SERVICE_CONTROL_NETBINDADD
0x00000007Notifies的网络服务是有约束力的新的组成部分。该hService处理必须有SERVICE_PAUSE_CONTINUE访问权限。但是,此控制码已被废弃,使用即插即用功能代替。
SERVICE_CONTROL_NETBINDDISABLE
0x0000000ANotifies网络服务,其绑定一个已被禁用。该hService处理必须有SERVICE_PAUSE_CONTINUE访问权限。但是,此控制码已被废弃,使用即插即用功能代替。
SERVICE_CONTROL_NETBINDENABLE
0x00000009Notifies网络服务,弱能约束力已被启用。该hService处理必须有SERVICE_PAUSE_CONTINUE访问权限。但是,此控制码已被废弃,使用即插即用功能代替。
SERVICE_CONTROL_NETBINDREMOVE
0x00000008Notifies的网络服务,一个有约束力的组成部分已被删除。该hService处理必须有SERVICE_PAUSE_CONTINUE访问权限。但是,此控制码已被废弃,使用即插即用功能代替。
SERVICE_CONTROL_PARAMCHANGE
0x00000006Notifies一,它的启动参数已经改变了服务。该hService处理必须有SERVICE_PAUSE_CONTINUE访问权限。
SERVICE_CONTROL_PAUSE
0x00000002Notifies一种服务,它应该暂停。该hService处理必须有SERVICE_PAUSE_CONTINUE访问权限。
SERVICE_CONTROL_STOP
0x00000001Notifies一种服务,它应该停止。该hService处理必须有SERVICE_STOP访问权限。
在发送停止请求到服务,您不应该将其他控件服务。
此参数也可以是一个用户定义的控制代码,如下表所述。
控制codeMeaning
范围128 255The服务定义与控制代码相关联的行动。该hService处理必须有SERVICE_USER_DEFINED_CONTROL访问权限。
dwInfoLevel [in]
为控制参数的信息服务Level。此参数必须设置为SERVICE_CONTROL_STATUS_REASON_INFO(1)。
pControlParams [ in , out ]
该项服务的控制参数的指针。如果dwInfoLevel是SERVICE_CONTROL_STATUS_REASON_INFO,该成员是一个指向SERVICE_CONTROL_STATUS_REASON_PARAMS结构的指针。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
下面的错误代码可以设置由服务控制管理器。其他的错误代码可以设置的注册表由服务控制管理器调用的函数。
返回codeDescription
ERROR_ACCESS_DENIEDThe处理不具备所需的访问权。
ERROR_DEPENDENT_SERVICES_RUNNINGThe服务不能停止,因为其他正在运行的服务依赖于它。
ERROR_INVALID_HANDLEThe指定的手柄没有得到使用CreateService或OpenService,或句柄不再有效。
ERROR_INVALID_PARAMETERThe要求在dwControl参数控制代码是不确定的,或dwControl是SERVICE_CONTROL_STOP但是,SERVICE_CONTROL_STATUS_REASON_PARAMS结构dwReason或pszComment成员无效。
ERROR_INVALID_SERVICE_CONTROLThe要求控制代码是无效的,或者是不能接受的服务。
ERROR_SERVICE_CANNOT_ACCEPT_CTRLThe要求控制代码不能被发送到服务,因为服务的状态SERVICE_STOPPED,SERVICE_START_PENDING,或SERVICE_STOP_PENDING。
ERROR_SERVICE_NOT_ACTIVEThe服务尚未启动。
ERROR_SERVICE_REQUEST_TIMEOUTThe的服务进程启动,但它并未要求StartServiceCtrlDispatcher,或线程调用StartServiceCtrlDispatcher可能会在控制处理功能受阻。
ERROR_SHUTDOWN_IN_PROGRESSThe系统正在关闭。
备注
ControlServiceEx功能要求的服务控制管理器(SCM)来发送请求的控制代码的服务。在SCM发送代码如果服务已经明确,将接受的代码,并在其中一控制代码可以被发送给它的状态。
供应链管理过程的一个串行方式服务控制通知-它等待一个服务发送前完成下一个处理一个服务控制通知。正因为如此,以30秒ControlServiceEx块调用的任何服务是忙于处理控制代码。如果在繁忙的服务还没有从它的处理功能,超时过期时返回ControlServiceEx失败,ERROR_SERVICE_REQUEST_TIMEOUT。
停止和启动服务,需要一个安全描述符,允许您这样做。默认的安全描述符允许LocalSystem帐户,以及Administrators和Power Users组的成员停止和启动服务。要改变一个服务的安全描述符,请修改为服务的DACL。
该QueryServiceStatusEx函数返回一个SERVICE_STATUS_PROCESS结构,其dwCurrentState和dwControlsAccepted成员显示当前状态和控制正在运行的服务所接受。所有正在运行的服务,接受默认SERVICE_CONTROL_INTERROGATE控制代码。司机不接受控制代码比SERVICE_CONTROL_STOP和SERVICE_CONTROL_INTERROGATE其他。每个服务指定其他控制代码,它接受当它调用SetServiceStatus函数来报告其状态。一项服务应经常接受这些代码在运行时,不管它是什么做什么。
下表显示了在可能的供应链管理服务的每一个国家的行动。
服务stateStopOther控制
停止(三)(三)
STOP_PENDING(二)(二)
START_PENDING(一)(二)
运行(1)(1)
CONTINUE_PENDING(1)(1)
PAUSE_PENDING(1)(1)
已暂停(1)(1)
(一)
如果服务接受这一控制代码,发送请求到服务,否则,ControlServiceEx返回0,GetLastError返回ERROR_INVALID_SERVICE_CONTROL。
(二)
该服务并不在其中一个控件可以发送给它的状态,因此ControlServiceEx返回零和GetLastError返回ERROR_SERVICE_CANNOT_ACCEPT_CTRL。
(三)
该服务不活跃,所以ControlServiceEx返回零和GetLastError返回ERROR_SERVICE_NOT_ACTIVE。

要求:
client最低支持Vista
server最低支持 Windows Server 2008
HeaderWinsvc.h(头文件:winuser.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode和ANSI namesControlServiceExW(Unicode)和ControlServiceExA(ANSI)的
参见
CreateService
OpenService
QueryServiceStatusEx
服务控制要求
服务函数
SERVICE_CONTROL_STATUS_REASON_PARAMS
SERVICE_STATUS
SetServiceObjectSecurity
SetServiceStatus
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==ControlServiceEx Function
Sends a control code to a service.
Syntax
C++
BOOL WINAPI ControlServiceEx(
__in SC_HANDLE hService,
__in DWORD dwControl,
__in DWORD dwInfoLevel,
__inout PVOID pControlParams
);
Parameters
hService [in]
A handle to the service. This handle is returned by the OpenService or CreateService function. The access rights required for this handle depend on the dwControl code requested.
dwControl [in]
This parameter can be one of the following control codes.
Control codeMeaning
SERVICE_CONTROL_CONTINUE
0x00000003Notifies a paused service that it should resume. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.
SERVICE_CONTROL_INTERROGATE
0x00000004Notifies 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.
SERVICE_CONTROL_NETBINDADD
0x00000007Notifies 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.
SERVICE_CONTROL_NETBINDDISABLE
0x0000000ANotifies 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.
SERVICE_CONTROL_NETBINDENABLE
0x00000009Notifies 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.
SERVICE_CONTROL_NETBINDREMOVE
0x00000008Notifies 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.
SERVICE_CONTROL_PARAMCHANGE
0x00000006Notifies a service that its startup parameters have changed. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.
SERVICE_CONTROL_PAUSE
0x00000002Notifies a service that it should pause. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.
SERVICE_CONTROL_STOP
0x00000001Notifies 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.

This parameter can also be a user-defined control code, as described in the following table.
Control codeMeaning
Range 128 to 255The service defines the action associated with the control code. The hService handle must have the SERVICE_USER_DEFINED_CONTROL access right.

dwInfoLevel [in]
The information level for the service control parameters. This parameter must be set to SERVICE_CONTROL_STATUS_REASON_INFO (1).
pControlParams [in, out]
A pointer to the service control parameters. If dwInfoLevel is SERVICE_CONTROL_STATUS_REASON_INFO, this member is a pointer to a SERVICE_CONTROL_STATUS_REASON_PARAMS structure.
Return Value
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.
Return codeDescription
ERROR_ACCESS_DENIEDThe handle does not have the required access right.
ERROR_DEPENDENT_SERVICES_RUNNINGThe service cannot be stopped because other running services are dependent on it.
ERROR_INVALID_HANDLEThe specified handle was not obtained using CreateService or OpenService , or the handle is no longer valid.
ERROR_INVALID_PARAMETERThe requested control code in the dwControl parameter is undefined, or dwControl is SERVICE_CONTROL_STOP but the dwReason or pszComment members of the SERVICE_CONTROL_STATUS_REASON_PARAMS structure are not valid.
ERROR_INVALID_SERVICE_CONTROLThe requested control code is not valid, or it is unacceptable to the service.
ERROR_SERVICE_CANNOT_ACCEPT_CTRLThe 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.
ERROR_SERVICE_NOT_ACTIVEThe service has not been started.
ERROR_SERVICE_REQUEST_TIMEOUTThe process for the service was started, but it did not call StartServiceCtrlDispatcher , or the thread that called StartServiceCtrlDispatcher may be blocked in a control handler function.
ERROR_SHUTDOWN_IN_PROGRESSThe system is shutting down.

Remarks
The ControlServiceEx function asks the Service Control Manager (SCM) to send the requested control code to the service. The SCM sends the code if the service has specified that it will accept the code, and is in a state in which a control code can be sent to it.
The SCM processes service control notifications in a serial fashion — it waits for one service to complete processing a service control notification before sending the next one. Because of this, a call to ControlServiceEx blocks for 30 seconds if any service is busy handling a control code. If the busy service still has not returned from its handler function when the timeout expires, ControlServiceEx fails with ERROR_SERVICE_REQUEST_TIMEOUT.
To stop and start a service requires a security descriptor that allows you to do so. The default security descriptor allows the LocalSystem account , and members of the Administrators and Power Users groups to stop and start services. To change the security descriptor of a service, see Modifying the DACL for a Service .
The QueryServiceStatusEx function returns a SERVICE_STATUS_PROCESS 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 SetServiceStatus 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 stateStopOther 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, ControlServiceEx returns zero and GetLastError returns ERROR_INVALID_SERVICE_CONTROL.
(b)
The service is not in a state in which a control can be sent to it, so ControlServiceEx returns zero and GetLastError returns ERROR_SERVICE_CANNOT_ACCEPT_CTRL.
(c)
The service is not active, so ControlServiceEx returns zero and GetLastError returns ERROR_SERVICE_NOT_ACTIVE.

Requirements
Minimum supported clientWindows Vista
Minimum supported serverWindows Server 2008
HeaderWinsvc.h (include Windows.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode and ANSI namesControlServiceExW (Unicode) and ControlServiceExA (ANSI)
See Also
CreateService
OpenService
QueryServiceStatusEx
Service Control Requests
Service Functions
SERVICE_CONTROL_STATUS_REASON_PARAMS
SERVICE_STATUS
SetServiceObjectSecurity
SetServiceStatus
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms682110(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:23:18