网站首页  词典首页

请输入您要查询的函数:

 

术语 startservice
释义 StartService
语法:
C++
BOOL WINAPI StartService(
__in SC_HANDLE hService,
__in DWORD dwNumServiceArgs,
__in_opt LPCTSTR *lpServiceArgVectors
);
StartService函数
启动服务。
参数
hService [in]
句柄的服务。这种处理是由OpenService或CreateService函数返回,它必须有SERVICE_START访问权限。有关更多信息,请参阅服务安全和访问权限。
dwNumServiceArgs [in]
在lpServiceArgVectors人数的字符串数组。如果lpServiceArgVectors为NULL,这个参数可以是零。
lpServiceArgVectors [中,可选]
空,要通过终止对作为参数提供服务的ServiceMain函数的字符串。如果没有参数,此参数可以为NULL。否则,第一个参数(lpServiceArgVectors [0])是服务的名称,其次是任何(lpServiceArgVectors [1]通过lpServiceArgVectors [dwNumServiceArgs - 1])的议论。
司机服务不接受这些观点。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
下面的错误代码可以设置由服务控制管理器。其他可以设置的注册表由服务控制管理器调用的函数。
返回codeDescription
ERROR_ACCESS_DENIEDThe处理不具备SERVICE_START访问权限。
ERROR_INVALID_HANDLEThe句柄无效。
ERROR_PATH_NOT_FOUNDThe服务二进制文件找不到。
ERROR_SERVICE_ALREADY_RUNNINGAn服务的实例已在运行。
ERROR_SERVICE_DATABASE_LOCKEDThe数据库已锁定。
ERROR_SERVICE_DEPENDENCY_DELETEDThe服务依赖服务不存在或已被标记为删除。
ERROR_SERVICE_DEPENDENCY_FAILThe服务依赖于另外一个未能启动服务。
ERROR_SERVICE_DISABLEDThe服务已被禁用。
ERROR_SERVICE_LOGON_FAILEDThe服务没有启动由于登录失败。如果出现此错误的服务配置下运行的帐户不具有“登录作为一种服务”的权利。
ERROR_SERVICE_MARKED_FOR_DELETEThe的服务已标记为删除。
ERROR_SERVICE_NO_THREADA线程不能创建的服务。
ERROR_SERVICE_REQUEST_TIMEOUTThe的服务进程启动,但它并未要求StartServiceCtrlDispatcher,或线程调用StartServiceCtrlDispatcher可能会在控制处理功能受阻。
备注
当司机的服务启动,StartService函数不会返回,直到该设备驱动程序已完成初始化。
当服务启动,服务控制管理器(SCM)产卵的服务过程中,如果必要的。如果指定的服务股与其他服务的过程中,所需要的过程可能已经存在。在StartService函数不会等待在新的更新服务第一的地位,因为它可能需要一段时间。相反,它返回时,单片机接收来自服务控制调度,要为这种服务的ServiceMain线程创建成功的通知。
在供应链管理从StartService之前设置以下默认返回状态值:
该服务的当前状态设置为SERVICE_START_PENDING。
控制接纳设置为none(零)。
检查点值设置为零。
该WaitHint时间设置为2秒。
调用进程可以判断新的服务,已完成调用QueryServiceStatus其初始化函数定期查询服务的地位。
一个服务无法调用初始化过程中StartService。原因是,供应链管理在初始化期间锁控制数据库的服务,因此对StartService调用将阻塞。该服务后报告,它已成功启动供应链管理,它可以调用StartService。
正如ControlService,StartService会阻止30秒,如果任何服务是忙于处理控制代码。如果在繁忙的服务还没有从它的处理功能,超时过期时返回,StartService失败,ERROR_SERVICE_REQUEST_TIMEOUT。这是因为供应链管理进程一次只能有一个服务控制通知。
实例
有关示例,请参阅启动一个服务。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinsvc.h(头文件:winuser.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode和ANSI namesStartServiceW(Unicode)和StartServiceA(ANSI)的
参见
ControlService
CreateService
DeleteService
OpenService
QueryServiceStatusEx
服务函数
服务启动
ServiceMain
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==StartService Function
Starts a service.
Syntax
C++
BOOL WINAPI StartService(
__in SC_HANDLE hService,
__in DWORD dwNumServiceArgs,
__in_opt LPCTSTR *lpServiceArgVectors
);
Parameters
hService [in]
A handle to the service. This handle is returned by the OpenService or CreateService function, and it must have the SERVICE_START access right. For more information, see Service Security and Access Rights .
dwNumServiceArgs [in]
The number of strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.
lpServiceArgVectors [in, optional]
The null-terminated strings to be passed to the ServiceMain function for the service as arguments. If there are no arguments, this parameter can be NULL. Otherwise, the first argument (lpServiceArgVectors[0]) is the name of the service, followed by any additional arguments (lpServiceArgVectors[1] through lpServiceArgVectors[dwNumServiceArgs-1]).
Driver services do not receive these arguments.
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. Others 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 SERVICE_START access right.
ERROR_INVALID_HANDLEThe handle is invalid.
ERROR_PATH_NOT_FOUNDThe service binary file could not be found.
ERROR_SERVICE_ALREADY_RUNNINGAn instance of the service is already running.
ERROR_SERVICE_DATABASE_LOCKEDThe database is locked.
ERROR_SERVICE_DEPENDENCY_DELETEDThe service depends on a service that does not exist or has been marked for deletion.
ERROR_SERVICE_DEPENDENCY_FAILThe service depends on another service that has failed to start.
ERROR_SERVICE_DISABLEDThe service has been disabled.
ERROR_SERVICE_LOGON_FAILEDThe service did not start due to a logon failure. This error occurs if the service is configured to run under an account that does not have the "Log on as a service" right.
ERROR_SERVICE_MARKED_FOR_DELETEThe service has been marked for deletion.
ERROR_SERVICE_NO_THREADA thread could not be created for the service.
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.

Remarks
When a driver service is started, the StartService function does not return until the device driver has finished initializing.
When a service is started, the Service Control Manager (SCM) spawns the service process, if necessary. If the specified service shares a process with other services, the required process may already exist. The StartService function does not wait for the first status update from the new service, because it can take a while. Instead, it returns when the SCM receives notification from the service control dispatcher that the ServiceMain thread for this service was created successfully.
The SCM sets the following default status values before returning from StartService:
Current state of the service is set to SERVICE_START_PENDING.
Controls accepted is set to none (zero).
The CheckPoint value is set to zero.
The WaitHint time is set to 2 seconds.
The calling process can determine if the new service has finished its initialization by calling the QueryServiceStatus function periodically to query the service's status.
A service cannot call StartService during initialization. The reason is that the SCM locks the service control database during initialization, so a call to StartService will block. After the service reports to the SCM that it has successfully started, it can call StartService.
As with ControlService , StartService will block 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, StartService fails with ERROR_SERVICE_REQUEST_TIMEOUT. This is because the SCM processes only one service control notification at a time.
Examples
For an example, see Starting a Service .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinsvc.h (include Windows.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode and ANSI namesStartServiceW (Unicode) and StartServiceA (ANSI)
See Also
ControlService
CreateService
DeleteService
OpenService
QueryServiceStatusEx
Service Functions
Service Startup
ServiceMain
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms686321(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 13:16:22