StartServiceCtrlDispatcher

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

StartServiceCtrlDispatcher

The StartServiceCtrlDispatcher function connects the main thread of a service process to the service control manager, which causes the thread to be the service control dispatcher thread for the calling process.

BOOL StartServiceCtrlDispatcher(
  const LPSERVICE_TABLE_ENTRY lpServiceTable
);
Parameters
lpServiceTable
[in] Pointer to an array of SERVICE_TABLE_ENTRY structures containing one entry for each service that can execute in the calling process. The members of the last entry in the table must have NULL values to designate the end of the table.
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 code 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_FAILED_SERVICE_CONTROLLER_CONNECTTypically, this error indicates that the program is being run as a console application rather than as a service.

If the program will be run as a console application for debugging purposes, structure it such that service-specific code is not called when this error is returned.

ERROR_INVALID_DATAThe specified dispatch table contains entries that are not in the proper format.
ERROR_SERVICE_ALREADY_RUNNINGThe process has already called StartServiceCtrlDispatcher. Each process can call StartServiceCtrlDispatcher only one time.
Windows NT:  This value is not supported.
Remarks

When the service control manager starts a service process, it waits for the process to call the StartServiceCtrlDispatcher function. The main thread of a service process should make this call as soon as possible after it starts up. If StartServiceCtrlDispatcher succeeds, it connects the calling thread to the service control manager and does not return until all running services in the process have terminated. The service control manager uses this connection to send control and service start requests to the main thread of the service process. The main thread acts as a dispatcher by invoking the appropriate HandlerEx function to handle control requests, or by creating a new thread to execute the appropriate ServiceMain function when a new service is started.

The lpServiceTable parameter contains an entry for each service that can run in the calling process. Each entry specifies the ServiceMain function for that service. For SERVICE_WIN32_SHARE_PROCESS services, each entry must contain the name of a service. This name is the service name that was specified by the CreateService function when the service was installed. For SERVICE_WIN32_OWN_PROCESS services, the service name in the table entry is ignored.

If a service runs in its own process, the main thread of the service process should immediately call StartServiceCtrlDispatcher. All initialization tasks are done in the service's ServiceMain function when the service is started.

If multiple services share a process and some common process-wide initialization needs to be done before any ServiceMain function is called, the main thread can do the work before calling StartServiceCtrlDispatcher, as long as it takes less than 30 seconds. Otherwise, another thread must be created to do the process-wide initialization, while the main thread calls StartServiceCtrlDispatcher and becomes the service control dispatcher. Any service-specific initialization should still be done in the individual service main functions.

Example Code

For an example, see Writing a ServiceMain Function.

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

Declared in Winsvc.h; include Windows.h.

Library

Link to Advapi32.lib.

DLLRequires Advapi32.dll.
Unicode

Implemented as StartServiceCtrlDispatcherW (Unicode) and StartServiceCtrlDispatcherA (ANSI).

Windows Service服务程序的原理及实现(0)服务主函数 & 控制处理函数 摘要: 何为服务?Windows 会话中可长时间运行的可执行应用程序。这些服务可以在计算机启动时自动启动,可以暂停和重新启动而且不显示任何用户界面。这种服务非常适合在服务器上使用,或任何时候,为了不影响在同一台计算机上工作的其他用户,需要长时间运行功能时使用。一个服务首先是一个Win32可执行程序,如果要写一个功能完备且强大的服务,需要熟悉动态连接库(DLL)、结构异常处理、内存映射文件、虚拟内存、 阅读详情

相关推荐

毕设案例|保安公司智慧管理系统的建设与开发方案

"保安公司智慧管理系统是一款专为保安行业设计的高效信息化解决方案,其核心功能涵盖了从人力资源管理到业务运营的各个方面。系统以Java作为开发语言,结合SpringMVC框架,确保了稳定性和可扩展性,而MySQL数据库则提供了强大的数据存储和处理能力。首先,系统允许用户设置各类保安,如门卫、巡逻员等,实现精细化分类管理。其次,保安信息管理模块包括详细的人事档案、资格证书、培训记录等,便于人员追踪和考核。部门和城市设置方便公司层级管理和异地项目管理。岗位设置与时间安排精确到分钟,确保排班科学合理。

muyu2980的专栏 938

Windows服务编程之服务程序

Windows服务程序

Fei_Liu的博客 6246

Android音频学习(八)——AudioFlinger线程

在 PlaybackThread 的实现中,Flag 用于标识线程的特殊行为或配置。

miemie2014的博客 1400

windows服务开发

windows服务开发

CAir2的专栏 1534

blenderproc 制作位姿估计数据集

blenderproc 制作位姿估计数据集 准备工作 1.首先需要去下载blenderproc的源码blenderproc,按照作者的readme文件进行编译。 2.其次需要下载bop_toolkit源码,链接如下bop_toolkit 3.说明:blenderproc主要用来生成数据,包括depth,rgb,位姿标签文件(scene_gt.json),bop_toolkit主要用来生成mask和mask_visib,scene_gt_info.json,用于判断物体的可见区域比例,如果遮挡太多考虑去掉。做

qq_43814359的博客 5699

Unity Spine动画控制全攻略:播放、回调与停止的实战技巧

本文深入解析Unity中Spine动画的核心控制技巧,涵盖动画播放、轨道分层、事件回调与平滑停止等实战方法。通过封装SpineAnimationController,详细讲解了如何利用动画播放结束回调实现精准的游戏逻辑同步,并提供了避免内存泄漏和动画卡顿的避坑指南,助力开发者打造流畅专业的2D游戏动画系统。

weixin_29021291的博客 381

ServiceMain、StartServiceCtrlDispatcher

VOID WINAPI ServiceMain(     DWORD dwArgc,     LPTSTR* lpszArgv); 服务主函数的参数与main函数的参数使用方法类似,但是服务主函数的参数不是通过在命令启动时设定的,而是通过SCM的相关API进行传递的(StartService函数)       SCM要对服务进行管理,就必须知道服务程序的服务主函数。服务程序通过调用Sta

bsx881220的专栏 1737

Cursor Cloud Agent:云原生编程工作流的底层重构

编程工作流正从本地计算范式转向云原生执行范式。Cloud Agent 本质是将代码理解、生成、执行与调试等核心能力下沉至隔离、可控、按需分配的云端虚拟机,通过 Firecracker 微虚拟机实现亚秒级启动,并依托上下文快照、环境镜像化和内核级沙箱保障一致性、算力弹性与数据安全。这一范式突破了传统本地 AI 编程助手在环境依赖、调试能力与企业合规上的根本局限,使 IDE 从编辑工具升维为分布式开发指挥中心。本文深入解析其运行机制与工程落地实践。

weixin_34354173的博客 337

StartServiceCtrlDispatcher时1063错误

https://docs.microsoft.com/zh-cn/windows/desktop/api/winsvc/nf-winsvc-startservicectrldispatchera MSDN如上 问题: 服务程序运行时发现在win10 64位机器总是出现1063ERROR_FAILED_SERVICE_CONTROLLER_CONNECT错误,服务列表里有但是运行后始终不起作用....

随机事件 3395

Windows非分页缓冲池内存泄漏实战:PoolMon与RAMMap高效排查指南

本文详细介绍了Windows系统中非分页缓冲池内存泄漏的实战排查方法。当系统出现卡顿且内存占用异常增长时,通过RAMMap工具快速定位非分页缓冲池异常,并利用PoolMon监控内核内存分配标签,精准锁定泄漏源。文章提供了从确认症状、安装工具到使用findstr命令溯源驱动文件的完整五步排查流程,并总结了常见泄漏标签与解决方案,帮助用户高效解决深层系统内存问题。

weixin_28455801的博客 1012

2026AI漫剧放心大胆做!小白也能轻松出片(附保姆级教程)

要是在2025,我大概率会劝他再等等,毕竟那时工具还没这么顺手。但到了2026年的今天,我的回答得很干脆:放心去做,绝对没问题。这一年多来,AI漫剧这块的变化真可谓翻天覆地。过去你想拍个像样的短片,哪怕再简陋,也得凑齐拍摄设备、找场地、找演员,后期剪辑更是折磨。但现在,时代变了,AI已经把创作的门槛踏平了。你不需要请演员,也不用操心灯光布景,更不用为剪辑特效烧钱。一个人,一台电脑,花几天时间就能做一部完整的AI漫剧。你只要有有想表达的故事,突发的灵感,剩下的,都能直接交给AI落地。

欢迎来到鸾姝淡月博客,专为程序员和编程爱好者打造的技术博客。我们分享编程语言趋势、开发工具、编程哲学、职业发展等,助你掌握新技术,优化技能,激发编程热情。 533

API StartServiceCtrlDispatcher I cant md1

 Welcome to my Blog,can we make friends?google_ad_client = "pub-6382933205019744";google_ad_width = 336;google_ad_height = 280;google_ad_format = "336x280_as";google_ad_type = "text_image";

huihuang1414的专栏 687

Adams Car——Adams car与Simulink联合仿真

Adams与simulink悬架联合仿真

Mr.邹的博客 2127

调程序的感慨,StartServiceCtrlDispatcher时1063错误

昨晚,将程序写完。预计今天上午调试成功之后,就放到windows 服务器上去跑。 期间,出现各种问题。 (1)StartServiceCtrlDispatcher时1063错误 【解决方法】:由于windows service程序,不允许调试,所以如果你硬要调试,这个函数就回返回1063错误。那么怎么解决呢?很简单,你不能直接用vs进行调试。你只能通过打日志的方式,去看程序运行的问题。而必须

奋斗,永不止步 9783

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Oracle 启动ControlTC时报错StartServiceCtrlDispatcher failed with err 1063.

1.首先需要在Hosts中设置一下ip 2.命名行运行:net start OracleDBConsoleTC

A little bit Step 2525

计算机控制技术及应用

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

SERVICE_TABLE_ENTRY

SERVICE_TABLE_ENTRYThe SERVICE_TABLE_ENTRY structure is used by the StartServiceCtrlDispatcher function to specify the ServiceMain function for a service that can run in the calling process.typedef st

小发猫 3708

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

2-Windows服务之相关API说明

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

weixin_40332490的博客 1215

DELPHI实现安装或删除一个服务

Windows NT、Windows 2000、Windows XP 都可以把程序做为服务启动。Delphi 也有向导直接帮助建立服务应用程序。当一个服务应用程序被建立后,就可以使用服务安装功能安装它。一个服务应用程序,必须完成 2 个关键的函数,即:StartServiceCtrlDispatcher 和 RegisterServiceCtrlHandler 后才能被系统做...

weixin_33875839的博客 374

Windows下Service服务程序开发

Windows服务程序就是运行在任务管理器中‘服务’选项卡下的程序,可以通过服务控制程序(SCM)进行启动、停止、暂停等操作; SCM程序的打开方式为:单击“开始搜索”框,键入 services.msc,然后按 Enter。截图如下: SCM(service control manager),它是一个系统服务(就是我们上面的截图),我们开发的程序的一生都是通过它控制的,如启动、停止等。 ...

1万+

Writing a Service Program's main Function

Writing a Service Programs main FunctionThe main function of a service program calls the StartServiceCtrlDispatcher function to connect to the SCM and start the control dispatcher thread. The dispatc

小发猫 1137

编写Windows服务应该注意的一些心得

心得一 :核心对象的引用计数        Windows系统中核心对象,比如窗口句柄,文件句柄,Event等等,在Windows的内部管理机制中全部采用引用计数方式管理,比如hService = CreateService(..),经过这次调用,系统中hService这个对象的的引用计数加1,而创建后如果不关闭再次通过OpenSCManager和OpenService打开的犹豫上次的服务句柄没有

铜板的专栏 1361

windows service程序步骤

<br /> 一个windows服务程序大体可以三步来写,其大体框架如下:<br /> 1// TestService.cpp : Defines the entry point for the console application.<br /> 2//<br /> 3<br /> 4 #include "stdafx.h"<br /> 5 #include <Windows.h><br /> 6<br /> 7 LPTSTR g_ServiceName = _T("TestService");<b

Gary's Blog --- A C++ programmer 1364
上一篇: SetServiceBits
下一篇: StartService
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值