SetServiceStatus
来源:互联网 发布:ubuntu vmware tools 编辑:程序博客网 时间:2024/06/11 18:19
SetServiceStatus
The SetServiceStatus function updates the service control manager's status information for the calling service.
<strong>BOOL SetServiceStatus( SERVICE_STATUS_HANDLE</strong> <em><a target=_blank class="synParam" href="http://blog.csdn.net/i_like_cpp/article/details/389533" style="color: rgb(51, 102, 153); text-decoration: none; "><span style="color:#002c99;">hServiceStatus</span></a></em><strong>, LPSERVICE_STATUS</strong> <em><a target=_blank class="synParam" href="http://blog.csdn.net/i_like_cpp/article/details/389533" style="color: rgb(51, 102, 153); text-decoration: none; "><span style="color:#002c99;">lpServiceStatus</span></a></em><strong>);</strong>
Parameters
- hServiceStatus
- [in] Handle to the status information structure for the current service. This handle is returned by theRegisterServiceCtrlHandlerEx 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.
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.
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:
- Checkpoint updates that occur when the service is in transition from one state to another.
- Fatal error updates that occur 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 thedwWin32ExitCode 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 = <ServiceName> terminated with the following error: <ExitCode>.
Example Code
For an example, see Writing a ServiceMain Function.
Requirements
Declared in Winsvc.h; include Windows.h.
Link to Advapi32.lib.
- SetServiceStatus
- SetServiceStatus
- note : SetServiceStatus
- QueryServiceStatus、SetServiceStatus:获取设置服务运行状态
- Android笔记 隐式意图vs显示意图+隐式意图打开短信应用demo
- WinCE Eboot中的网络函数
- MFC三种不同方式实现图形的保存和重绘---方法二: 运用CMetaFileDC
- WPF附加事件定义
- 插入排序
- SetServiceStatus
- 物化视图
- PHP CURL 中文说明
- 读围城论方鸿渐与孙柔嘉的爱情
- 动态数组的申请与鞍点的测算
- Python实战——用urllib.urlretrieve自动下载推女郎套图
- iOS开发之CocoaPods(objective-c第三方库管理工具)
- Fiddler 教程
- JavaScipt中作为一等公民的函数