RegisterServiceCtrlHandler
2005-06-07 12:02
190 查看
RegisterServiceCtrlHandler
A service calls the RegisterServiceCtrlHandler function to register a function to handle its service control requests.This function has been superseded by the RegisterServiceCtrlHandlerEx function. A service can use either function, but the new function supports user-defined context data, and the new handler function supports additional extended control codes.
SERVICE_STATUS_HANDLE RegisterServiceCtrlHandler( LPCTSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc);
Parameters
lpServiceName [in] Pointer to a null-terminated string that specifies the name of the service run by the calling thread. This is the service name that the service control program specified in the CreateService function when creating the service. If the service type is SERVICE_WIN32_OWN_PROCESS, the function does not verify that the specified name is valid, because there is only one registered service in the process.lpHandlerProc [in] Pointer to the handler function to be registered. For more information, see Handler.
Return Values
If the function succeeds, the return value is a service status handle.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 code | Description |
---|---|
ERROR_INVALID_NAME | The specified service name is invalid. |
ERROR_SERVICE_DOES_NOT_EXIST | The specified service does not exist. |
Remarks
The ServiceMain function of a new service should immediately call the RegisterServiceCtrlHandler function to register a control handler function with the control dispatcher. This enables the control dispatcher to invoke the specified function when it receives control requests for this service. The threads of the calling process can use the service status handle returned by this function to identify the service in subsequent calls to the SetServiceStatus function.The RegisterServiceCtrlHandler function must be called before the first SetServiceStatus call because RegisterServiceCtrlHandler returns a service status handle for the caller to use so that no other service can inadvertently set this service status. In addition, the control handler must be in place to receive control requests by the time the service specifies the controls it accepts through the SetServiceStatus function.
When the control handler function is invoked with a control request, it must call SetServiceStatus to notify the service control manager of its current status, regardless of whether the status of the service has changed.
The service status handle does not have to be closed.
Example Code
For an example, see Writing a ServiceMain Function.Requirements
Client | Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation. |
---|---|
Server | Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server. |
Header | Declared in Winsvc.h; include Windows.h. |
Library | Link to Advapi32.lib. |
DLL | Requires Advapi32.dll. |
Unicode | Implemented as RegisterServiceCtrlHandlerW (Unicode) and RegisterServiceCtrlHandlerA (ANSI). |
相关文章推荐
- RegisterServiceCtrlHandlerEx
- Writing a ServiceMain Function(使用RegisterServiceCtrlHandler函数)
- ORA-12519: TNS:no appropriate service handler found 解决
- 处理程序“WebServiceHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- HTTP could not register URL http://+:8000/testservice/. Your...
- WCF Error RANT: An error occured creating the configuration section handler for system.serviceModel/
- [Android实例] Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
- 第四章 Android开发三大基石—Activity、Service和Handler(5)
- Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler d
- OERR: ORA-12519 TNS:no appropriate service handler found
- ORA-12519,TNS:no appropriate service handler found
- ORA-12519: TNS:no appropriate service handler found 解决
- android 线程(AsyncTask,Threadhandler,intentService)详解
- ORA-12519: TNS:no appropriate service handler found 解决
- Android中的HandlerThread和IntentService
- ORA-12519: TNS:no appropriate service handler found 解决
- ORA-12519: TNS:no appropriate service handler f...
- Android IntentService完全解析 当Service遇到Handler
- Android HandlerThread和IntentService用法和源码解析
- 异步图片下载引擎(升级版——ExecutorService+handler)