HandlerEx

[Win32] 服务程序开发(1)基本概念和服务程序的框架 一。服务程序基本概念 二。服务程序的编写框架 1。StartServiceCtrlDispatcher函数 BOOL WINAPI StartServiceCtrlDispatcher( _In_ const SERVICE_TABLE_ENTRY *lpServiceTable ); 函数功能:连接到服务控制管理器 参数:一个SERVICE_TABLE_ENTRY结构的指针 阅读详情

HandlerEx

A HandlerEx function is an application-defined callback function used with the RegisterServiceCtrlHandlerEx function. A service program can use it as the control handler function of a particular service.

The LPHANDLER_FUNCTION_EX type defines a pointer to this function. HandlerEx is a placeholder for the application-defined name.

This function supersedes the Handler control handler function used with the RegisterServiceCtrlHandler function. A service can use either control handler, but the new control handler supports user-defined context data and additional extended control codes.

DWORD WINAPI HandlerEx(
  DWORD dwControl,
  DWORD dwEventType,
  LPVOID lpEventData,
  LPVOID lpContext
);
Parameters
dwControl
[in] Control code. This parameter can be one of the following values.
Control codeMeaning
SERVICE_CONTROL_CONTINUE
0x00000003
Notifies a paused service that it should resume.
SERVICE_CONTROL_INTERROGATE
0x00000004
Notifies a service to report its current status information to the service control manager.
SERVICE_CONTROL_NETBINDADD
0x00000007
Notifies a network service that there is a new component for binding. The service should bind to the new component.

Applications should use Plug and Play functionality instead.

SERVICE_CONTROL_NETBINDDISABLE
0x0000000A
Notifies a network service that one of its bindings has been disabled. The service should reread its binding information and remove the binding.

Applications should use Plug and Play functionality instead.

SERVICE_CONTROL_NETBINDENABLE
0x00000009
Notifies a network service that a disabled binding has been enabled. The service should reread its binding information and add the new binding.

Applications should use Plug and Play functionality instead.

SERVICE_CONTROL_NETBINDREMOVE
0x00000008
Notifies a network service that a component for binding has been removed. The service should reread its binding information and unbind from the removed component.

Applications should use Plug and Play functionality instead.

SERVICE_CONTROL_PARAMCHANGE
0x00000006
Notifies a service that service-specific startup parameters have changed. The service should reread its startup parameters.
SERVICE_CONTROL_PAUSE
0x00000002
Notifies a service that it should pause.
SERVICE_CONTROL_SHUTDOWN
0x00000005
Notifies a service that the system is shutting down so the service can perform cleanup tasks.

For more information, see the Remarks section of this topic.

SERVICE_CONTROL_STOP
0x00000001
Notifies a service that it should stop.

If a service accepts this control code, it must stop upon receipt. After the SCM sends this control code, it will not send other control codes.

Windows XP/2000:  If the service returns NO_ERROR and continues to run, it continues to receive control codes. This behavior changed starting with Windows Server 2003 and Windows XP SP2.

This parameter can also be one of the following extended control codes. Note that these control codes are not supported by the Handler function.

Control CodeMeaning
SERVICE_CONTROL_DEVICEEVENT
0x0000000B
Notifies a service of device events. (The service must have registered to receive these notifications using the RegisterDeviceNotification function.)
SERVICE_CONTROL_HARDWAREPROFILECHANGE
0x0000000C
Notifies a service that the computer's hardware profile has changed.
SERVICE_CONTROL_POWEREVENT
0x0000000D
Notifies a service of system power events.
SERVICE_CONTROL_SESSIONCHANGE
0x0000000E
Notifies a service of session change events.
Windows 2000:  This value is not supported.

This parameter can also be a user-defined control code, as described in the following table.

Control codeMeaning
Range 128 to 255.The service defines the action associated with the control code.
dwEventType
[in] Type of event that has occurred. This parameter is used if dwControl is SERVICE_CONTROL_DEVICEEVENT, SERVICE_CONTROL_HARDWAREPROFILECHANGE, SERVICE_CONTROL_POWEREVENT, or SERVICE_CONTROL_SESSIONCHANGE. Otherwise, it is zero.

If dwControl is SERVICE_CONTROL_DEVICEEVENT, this parameter can be one of the following values:

If dwControl is SERVICE_CONTROL_HARDWAREPROFILECHANGE, this parameter can be one of the following values:

If dwControl is SERVICE_CONTROL_POWEREVENT, this parameter can be one of the values specified in the wParam parameter of the WM_POWERBROADCAST message.

If dwControl is SERVICE_CONTROL_SESSIONCHANGE, this parameter can be one of the values specified in the wParam parameter of the WM_WTSSESSION_CHANGE message.

lpEventData
[in] Additional device information, if required. The format of this data depends on the value of the dwControl and dwEventType parameters. If dwEventType is SERVICE_CONTROL_DEVICEEVENT, this data corresponds to the lParam parameter that applications receive as part of a WM_DEVICECHANGE message. If dwEventType is SERVICE_CONTROL_POWEREVENT, this data corresponds to the lParam parameter that applications receive as part of a WM_POWERBROADCAST message. If dwEventType is SERVICE_CONTROL_SESSIONCHANGE, this parameter is a WTSSESSION_NOTIFICATION structure.
lpContext
[in] User-defined data passed from RegisterServiceCtrlHandlerEx. When multiple services share a process, the lpContext parameter can help identify the service.
Return Values

The return value for this function depends on the control code received. The following list identifies the rules for this return value:

  • If your service does not handle the control, return ERROR_CALL_NOT_IMPLEMENTED.
  • If your service handles SERVICE_CONTROL_DEVICEEVENT, return NO_ERROR to grant the request and an error code to deny the request.
  • If your service handles SERVICE_CONTROL_HARDWAREPROFILECHANGE, return NO_ERROR to grant the request and an error code to deny the request.
  • If your service handles SERVICE_CONTROL_POWEREVENT, return NO_ERROR to grant the request and an error code to deny the request.
  • For all other control codes your service handles, return NO_ERROR.
Remarks

When a service is started, its ServiceMain function should immediately call the RegisterServiceCtrlHandlerEx function to specify a HandlerEx function to process control requests. To specify the control codes to be accepted, use the SetServiceStatus and RegisterDeviceNotification functions.

The control dispatcher in the main thread of a service invokes the control handler function for the specified service whenever it receives a control request from the service control manager. After processing the control request, the control handler must call SetServiceStatus to report its current status to the service control manager.

When the service control manager sends a control code to a service, it waits for the handler function to return before sending additional control codes to other services. If the handler function does not return promptly, it may block other services from receiving control codes.

The SERVICE_CONTROL_SHUTDOWN control code should only be processed by services that must absolutely clean up during shutdown, because there is a limited time (about 20 seconds) available for service shutdown. After this time expires, system shutdown proceeds regardless of whether service shutdown is complete. Note that if the system is left in the shutdown state (not restarted or powered down), the service continues to run.

If the service needs more time to clean up, it should send STOP_PENDING status messages, along with a wait hint, so the service controller knows how long to wait before reporting to the system that service shutdown is complete. However, to prevent a service from stopping shutdown, there is a limit to how long the service controller waits. To change this time limit, modify the WaitToKillServiceTimeout value in the following registry key:

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control

Be sure to handle Plug and Play device events as quickly as possible; otherwise, the system may become unresponsive. If your event handler is to perform an operation that may block execution (such as I/O), it is best to start another thread to perform the operation asynchronously.

Requirements
ClientRequires Windows XP or Windows 2000 Professional.
ServerRequires Windows Server 2003 or Windows 2000 Server.
Header

Declared in Winsvc.h; include Windows.h.

StartServiceCtrlDispatcher函数 将服务进程的主线程连接到服务控制管理器,这使得线程成为调用进程的服务控制调度程序线程。 语法 BOOL WINAPI StartServiceCtrlDispatcher( _In_ const SERVICE_TABLE_ENTRY * lpServiceTable ); 参数 lpServiceTable [in] 指向SERVICE_TABLE_ENTRY结构数组... 阅读详情

相关推荐

【AI深究】合成数据(Synthetic Data)深度解析:原理、算法与工程实践——全网最详细流程|核心原理、主流方法、数学表达、工程实践与细节、未来趋势|GAN、VAE、语言模型LLM合成如GPT

大家好,我是爱酱。本篇延续将会系统梳理合成数据(Synthetic Data)的核心原理、主流方法、数学表达、工程实践与未来趋势,结合数学公式,帮助你全面理解这一AI建模的关键技术。 注:本文章含大量数学算式、详细例子说明及大量代码演示,大量干货,建议先收藏再慢慢观看理解。新频道发展不易,你们的每个赞、收藏跟转发都是我继续分享的动力!

AI人工智能爱酱~你的AI学习好帮手~ 4937

windows系统睡眠与合上盖子事件捕获

gb173652770的专栏 4239

汽车OTA安全启动:ECU双验签机制与实战排障指南

汽车OTA升级中的安全启动,本质是基于密码学的信任建立过程,其核心在于ECU上电时对固件镜像的可信验证。该机制依托硬件信任根(Secure Boot ROM),通过RSA/ECDSA等非对称算法完成签名验签,确保升级包未被篡改且来源可信。技术价值体现在防止恶意固件注入、支撑功能安全(ASIL)与信息安全(ISO/SAE 21434)合规。典型应用场景包括4S店远程升级、BMS控制器固件更新及多ECU协同启动。实践中,验签名失败往往源于证书链断裂、Flash布局错位或KeyUsage字段不匹配等底层工程细节,

weixin_29314405的博客 77

Windows系统服务编程

Windows系统服务编程 1.简介 系统服务是后台进程运行的程序,没有界面。它是通过服务管理控制器(Service Control Manager, SCM)管理的,SCM可以操作系统服务启动、停止、自动运行等。 SCM提供的功能: (1)服务程序: 一种为一个或多个服务提供可执行代码的程序。服务程序使用连接到SCM并将状态信息发送到SCM的功能。 (2)服务配置程序: 查询或修改服务数据库的程...

hallyz的博客 1646

运算放大器电路仿真实践:从零实现完整示例

通过一个完整的运算放大器电路仿真示例,深入掌握电路仿真的关键步骤与技巧,帮助电子爱好者和工程师快速上手实际项目设计。

weixin_34725745的博客 1320

DrissionPage实战:5分钟搞定京东滑块验证码自动登录(附完整轨迹生成代码)

本文详细介绍了如何使用DrissionPage工具实现京东滑块验证码的自动化登录,包括环境配置、滑块缺口识别、拟人化轨迹生成算法及完整登录流程。通过物理运动学模型和智能识别技术,有效提升验证码破解成功率,适用于电商自动化场景。

weixin_29229055的博客 244

3. 服务应用程序

Microsoft Windows作业系统提供了许多工具让服务器端之主从式应用程序部份的实作变得更容易。如您所知,一个服务器即是一个履行服务器端义务的Windows应用程序。事实上,Microsoft BackOffice Logo程序即要求服务器应用程序应被实作成如同服务(services)一般的程序。服务是含有附加基础,允许它根据作业系统而受到特别处理的一般Windows应用程序,例如

showna的专栏 4341

U8-固定资产月末结账报错:BOF或EOF中有一个是真

度了下,发现此问题一般是由于fa_Vtsobject表缺少对应月份的记录导致,补上即可,但是查看发现此表记录正常。 跟踪后发现定位到以下语句: select * from AccInformation where cSysID = N'FA' and cName =N'bVoucherApply'上述语句执行后没有任何记录显示,但是在正常的账套执行是有记录的,那有可能就是记录丢失导致,执行以下

guizhouakun的博客 5921

Handler

HandlerA Handler function is an application-defined callback function used with the RegisterServiceCtrlHandler function. A service program uses it as the control handler function of a particular servi

小发猫 1200

手把手教你为STM32设备生成自定义MAC地址(基于芯片ID的5种算法对比)

本文详细介绍了基于STM32芯片ID生成自定义MAC地址的5种算法,包括直接截取、异或折叠、CRC32哈希、自定义混合运算及SHA-256摘要。通过对比分析各算法的计算复杂度、唯一性及适用场景,帮助嵌入式开发者根据项目规模与资源,选择最合适的方案,确保设备MAC地址的唯一性与合规性。

weixin_29170327的博客 528

虚幻商城 Quixel 免费资产一键入库

在免费领取所有Megascans之后,我们只是有了获取 Quixel Megascans 资产的资格,但是没有入 Fab 库,本文将讲解通过脚本将 Quixel 所有资产入库 Fab。

一碗清深的博客 3347

VC++ Service编程(六)Control Handler函数

Control Handler函数     每个服务都有一个控制处理器,HandlerEx函数。当服务程序从一个服务控制程序那里收到一个控制请求时,HandlerEx函数就会被控制调度器调用。因此,这个函数运行在控制调度器的环境中。服务调用RegisterServiceCtrlHandler或者RegisterServiceCtrlHandlerEx函数来注册它的Control Hand

Wang Shen 3509

MATLAB和S7-1200PLC水箱液位高度PID控制联合仿真(KEPserverOPC通信应用)

SMART PLC 向导PID的详细介绍请查看下面文章链接:S7-200 SMART PLC PID向导详细介绍(如何实现P、PD、PID控制器)-优快云博客文章浏览阅读1k次。这篇博客主要介绍SMART PLC PID向导的使用,PID控制相关的其它内容请查看专栏系列文章,常用链接如下:SMART PLC PID负压控制(过程量为负数)_负压控制pid控制程序_RXXW_Dor的博客-优快云博客1、如何实现PID反作用调节?S7-1200PLC和KEPserver OPC通信-优快云博客。

RXXW_Dor的博客 1781

Windows服务程序开发终极指南:从零开始构建高效后台服务

Windows服务是在后台运行的应用程序,能够在系统启动时自动启动,无需用户交互即可执行关键任务。本文将通过Windows-classic-samples项目中的实战案例,带你快速掌握服务开发的核心技术,从基础架构到高级功能,打造稳定可靠的后台服务解决方案。 ## 一、Windows服务核心概念与架构 Windows服务(Windows Service)是一种特殊的可执行程序,它运行在Wind

gitblog_01144的博客 978

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

用C++编制Win32 Service (二)

名词: Service Control Manager,服务控制管理器,简称SCM。 Service Control Dispatcher,服务控制发送器,简称SCD。 Service Process,服务进程,通常是一个Win32控制台应用程序(exe),由SCM负责启动。 Service Status,(当前)服务状态,当SCM向服务进程查询状态时,

于无声处 2556

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Windows系统编程之编写Windows服务(1)

一、Windows服务简介:  Windows服务,也称NT服务,提供将服务器转换为可以用命令或者在启动时初始化的服务所需的管理能力,初始化发生 在任何用户登录之 前,服务可以暂停、恢复、终止、监控。 注册表维护与服务的有关信息。 Windows的所有服务在如下图所示位置: 使用Windows 服务功能的情况很多,比如DNS客户、许多Sql Server服务

小米的修行之路 837

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Windows2000 服务器端应用程序开发设计指南-服务应用程序

Microsoft Windows作业系统提供了许多工具让服务器端之主从式应用程序部份的实作变得更容易。如您所知,一个服务器即是一个履行服务器端义务的Windows应用程序。事实上,Microsoft BackOffice Logo程序即要求服务器应用程序应被实作成如同服务(services)一般的程序。服务是含有附加基础,允许它根据作业系统而受到特别处理的一般Windows应用程序,例如,远

求索 3272

Spring MVC的运行流程

转载至:https://blog.youkuaiyun.com/qq_30646539/article/details/81700764 Spring MVC工作流程图 图一 图二 图三 Spring工作流程描述 1. 用户向服务器发送请求,请求被Spring 前端控制Servelt DispatcherServlet捕获; 2. DispatcherServlet对请求URL进行解析,得到请求资源标识符(URI)。然后根据该URI,调用HandlerMapping获得该Handler配置的所有相关的对

zqj1172102457的博客 207

OpenClaw Windows后台服务化部署全指南

Windows服务是操作系统级的后台进程管理机制,通过NT Service模型实现无界面、自启、崩溃自愈的长期运行。其核心原理在于Session 0隔离、非交互式上下文与服务控制管理器(SCM)协同调度,技术价值在于保障本地AI工作流引擎(如OpenClaw)的生产级稳定性与权限安全性。典型应用场景包括剪贴板监听、文件自动化、LLM技能调度等无需人工干预的智能办公任务。本文聚焦OpenClaw在Windows平台的服务化封装实践,详解NSSM服务包装器配置、Session 0适配、日志重定向与热重载集成等关

dechen6073的博客 449

对Delphi 7/Delphi 2007的Windows服务类库的一个小改进

Windows 2000以上的Windows版本所支持的Windows服务的功能有所改进,其变化体现在AdvApi32.dll中。其新增的函数包括: ChangeServiceConfig2 QueryServiceConfig2 EnumServicesStatusEx QueryServiceStatusEx RegisterService...

weixin_34112030的博客 75

2-Windows服务之相关API说明

它将等待一个服务完成对服务控制通知的处理,然后再发送下一个服务控制通知。在32位机器上,如果设置了服务依赖(例如:lpDependencies参数设置为Tcpip),则lpLoadOrderGroup参数不能设置为NULL,而需要设置为“”空字符串,否则函数会报错,GetLastError()返回1059(指定了循环服务依赖关系),原因未知。ControlService函数要求SCM发送指定的控制码给服务,如果服务已指定将接受代码,并且处于可以向其发送控制码的状态,则SCM将发送指定的控制码。

weixin_40332490的博客 1215

如何在服务程序中监听硬件事件

主要通过RegisterDeviceNotification函数来完成,网上一般能找到都是window程序,很少缺少服务程序的例子。 1. 从网上下载一个服务程序的框架。 2.svcmain 函数中 DEV_BROADCAST_DEVICEINTERFACE  dev_broadcast_deviceinterface = {0};     dev_broadcast_devicei

lvronglee的专栏 5182

分析-ReadFile读取物理磁盘参数错误(87)问题

Windows读取物理磁盘很简单,通过文件操作相关API即可实现,如: handle = CreateFileA("\\\\.\\physicaldrive0",...); ReadFile(handle,...); CloseHandle(handle);

柳似烟的专栏 4132

windows服务程序初探

<br />// serviceProgram.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <Windows.h> //服务程序:当一个应用程序需要常驻系统,或者随时为其它应用程序提供服务时,可以使用服务应用程序 SERVICE_STATUS g_SplSrvServieStatus; SERVICE_STATUS_HANDLE g_SplSrvService

一步一步 886
上一篇: Handler
下一篇: OpenSCManager
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值