网站首页  词典首页

请输入您要查询的函数:

 

术语 setservicestatus
释义 SetServiceStatus
语法:
C++
BOOL WINAPI SetServiceStatus(
__in SERVICE_STATUS_HANDLE hServiceStatus,
__in LPSERVICE_STATUS lpServiceStatus
);
SetServiceStatus函数
更新服务控制管理器的呼叫服务的状态信息。
参数
hServiceStatus [in]
一个句柄,当前服务的状态信息结构。这种处理是由RegisterServiceCtrlHandlerEx函数返回。
lpServiceStatus [in]
向SERVICE_STATUS结构包含了最新的呼叫服务的状态信息的指针。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
下面的错误代码可以设置由服务控制管理器。其他的错误代码可以设置的注册表由服务控制管理器调用的函数。
返回codeDescription
ERROR_INVALID_DATAThe指定的服务状态结构无效。
ERROR_INVALID_HANDLEThe指定的句柄无效。
备注
阿ServiceMain函数首先调用RegisterServiceCtrlHandlerEx函数来获取服务的SERVICE_STATUS_HANDLE。然后立即调用SetServiceStatus函数来通知服务控制管理器,它的地位SERVICE_START_PENDING。在初始化过程中,该服务可以提供的最新情况,表明它正在取得进展,但需要更多时间。一个常见的错误是让主线程执行初始化,而一个单独的线程继续呼吁SetServiceStatus标记,以防止它的服务控制管理器作为鸿的服务。但是,如果主线程挂起,那么服务启动733297一个无限循环,因为工作线程继续报告主线程正在取得进展。
处理后的控制要求,该服务的处理函数必须调用SetServiceStatus如果服务状态更改报告其新的地位,服务控制管理器。只有这样做有必要时,服务正在改变,如处理时,停止或关闭的控制状态。还可一个服务使用任何服务的任何线程的时间通知该功能,例如当服务必须停止由于可恢复的错误的状态变化,服务控制管理器。
一个服务可以调用后,才呼吁RegisterServiceCtrlHandlerEx获得服务状态处理这个功能。
如果服务调用设置为SERVICE_STOPPED的dwCurrentState成员和dwWin32ExitCode成员设置为一个非零值SetServiceStatus,下面的项被写入到系统事件日志中:
事件ID = 7023
来源=服务控制管理器
类型=错误
说明= 因以下错误:

以下是最佳做法,在调用这个函数:
初始化所有领域,在SERVICE_STATUS结构,确保有有效的检查点,并等待等待状态提示值。使用合理的等待提示。
没有登记接受控制,同时状态是SERVICE_START_PENDING或服务可以崩溃。初始化完成后,接受SERVICE_CONTROL_STOP代码。
与检查站和呼叫等待提示的价值只有在服务正在就有关悬而未决的启动,停止,暂停或继续经营的任务进展情况的功能。否则,供应链管理,如果无法检测到您的服务挂起。
进入适当的退出代码停止状态,如果ServiceMain失败。
如果状态是SERVICE_STOPPED,调用SetServiceStatus一次只。这一功能,因此是对供应链管理LRPC呼吁。第一个调用的SERVICE_STOPPED状态的功能关闭的RPC上下文句柄和任何后续调用可能导致崩溃的过程。
实例
有关示例,请参见编写一ServiceMain函数。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinsvc.h(头文件:winuser.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
参见
HandlerEx
RegisterServiceCtrlHandlerEx
服务函数
SERVICE_STATUS
ServiceMain
SetServiceBits
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==SetServiceStatus Function
Updates the service control manager's status information for the calling service.
Syntax
C++
BOOL WINAPI SetServiceStatus(
__in SERVICE_STATUS_HANDLE hServiceStatus,
__in LPSERVICE_STATUS lpServiceStatus
);
Parameters
hServiceStatus [in]
A handle to the status information structure for the current service. This handle is returned by the RegisterServiceCtrlHandlerEx function.
lpServiceStatus [in]
A pointer to the SERVICE_STATUS structure the contains the latest status information for the calling service.
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_INVALID_DATAThe specified service status structure is invalid.
ERROR_INVALID_HANDLEThe specified handle is invalid.

Remarks
A ServiceMain function first calls the RegisterServiceCtrlHandlerEx function to get the service's SERVICE_STATUS_HANDLE. Then it immediately calls the SetServiceStatus function to notify the service control manager that its status is SERVICE_START_PENDING. During initialization, the service can provide updated status to indicate that it is making progress but it needs more time. A common bug is for the service to have the main thread perform the initialization while a separate thread continues to call SetServiceStatus to prevent the service control manager from marking it as hung. However, if the main thread hangs, then the service start ends up in an infinite loop because the worker thread continues to report that the main thread is making progress.
After processing a control request, the service's Handler function must call SetServiceStatus if the service status changes to report its new status to the service control manager. It is only necessary to do so when the service is changing state, such as when it is processing stop or shutdown controls. A service can also use this function at any time from any thread of the service to notify the service control manager of state changes, such as when the service must stop due to a recoverable error.
A service can call this function only after it has called RegisterServiceCtrlHandlerEx to get a service status handle.
If a service calls SetServiceStatus with the dwCurrentState member set to SERVICE_STOPPED and the dwWin32ExitCode member set to a nonzero value, the following entry is written into the System event log:
Event ID = 7023
Source = Service Control Manager
Type = Error
Description = terminated with the following error:
.
The following are best practices when calling this function:
Initialize all fields in the SERVICE_STATUS structure, ensuring that there are valid check-point and wait hint values for pending states. Use reasonable wait hints.
Do not register to accept controls while the status is SERVICE_START_PENDING or the service can crash. After initialization is completed, accept the SERVICE_CONTROL_STOP code.
Call this function with checkpoint and wait-hint values only if the service is making progress on the tasks related to the pending start, stop, pause, or continue operation. Otherwise, SCM cannot detect if your service is hung.
Enter the stopped state with an appropriate exit code if ServiceMain fails.
If the status is SERVICE_STOPPED, call SetServiceStatus one time only. This function makes an LRPC call to the SCM. The first call to the function in the SERVICE_STOPPED state closes the RPC context handle and any subsequent calls can cause the process to crash.
Examples
For an example, see Writing a ServiceMain Function .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinsvc.h (include Windows.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
See Also
HandlerEx
RegisterServiceCtrlHandlerEx
Service Functions
SERVICE_STATUS
ServiceMain
SetServiceBits
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms686241(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:21:53