ControlService

[Win32] SCManager 服务控制管理器API(1) 1。OpenSCManager 打开服务控制管理器 函数原型: SC_HANDLE WINAPI OpenSCManager( _In_opt_ LPCTSTR lpMachineName, _In_opt_ LPCTSTR lpDatabaseName, _In_ DWORD dwDesiredAccess );lpMachineName:置NULL lpD 阅读详情

ControlService

The ControlService function sends a control code to a service.

BOOL ControlService(
  SC_HANDLE hService,
  DWORD dwControl,
  LPSERVICE_STATUS lpServiceStatus
);
Parameters
hService
[in] Handle to the service. This handle is returned by the OpenService or CreateService function. The access rights required for this handle depend on the dwControl code requested.
dwControl
[in] This parameter can be one of the following control codes.
Control codeMeaning
SERVICE_CONTROL_CONTINUE
0x00000003
Notifies a paused service that it should resume. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.
SERVICE_CONTROL_INTERROGATE
0x00000004
Notifies a service that it should report its current status information to the service control manager. The hService handle must have the SERVICE_INTERROGATE access right.
SERVICE_CONTROL_NETBINDADD
0x00000007
Notifies a network service that there is a new component for binding. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead.
Windows NT:  This value is not supported.
SERVICE_CONTROL_NETBINDDISABLE
0x0000000A
Notifies a network service that one of its bindings has been disabled. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead.
Windows NT:  This value is not supported.
SERVICE_CONTROL_NETBINDENABLE
0x00000009
Notifies a network service that a disabled binding has been enabled. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead.
Windows NT:  This value is not supported.
SERVICE_CONTROL_NETBINDREMOVE
0x00000008
Notifies a network service that that a component for binding has been removed. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead.
Windows NT:  This value is not supported.
SERVICE_CONTROL_PARAMCHANGE
0x00000006
Notifies a service that its startup parameters have changed. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.
Windows NT:  This value is not supported.
SERVICE_CONTROL_PAUSE
0x00000002
Notifies a service that it should pause. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.
SERVICE_CONTROL_STOP
0x00000001
Notifies a service that it should stop. The hService handle must have the SERVICE_STOP access right.

After sending the stop request to a service, you should not send other controls to the service.

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

Control codeMeaning
Range 128 to 255The service defines the action associated with the control code. The hService handle must have the SERVICE_USER_DEFINED_CONTROL access right.
lpServiceStatus
[out] Pointer to a SERVICE_STATUS structure that receives the latest service status information. The information returned reflects the most recent status that the service reported to the service control manager.

The service control manager fills in the structure only when ControlService returns one of the following error codes: NO_ERROR, ERROR_INVALID_SERVICE_CONTROL, ERROR_SERVICE_CANNOT_ACCEPT_CTRL, or ERROR_SERVICE_NOT_ACTIVE. Otherwise, the structure is not filled in.

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.

Return codeDescription
ERROR_ACCESS_DENIEDThe handle does not have the required access right.
ERROR_DEPENDENT_SERVICES_RUNNINGThe service cannot be stopped because other running services are dependent on it.
ERROR_INVALID_HANDLEThe specified handle was not obtained using CreateService or OpenService, or the handle is no longer valid.
ERROR_INVALID_PARAMETERThe requested control code is undefined.
ERROR_INVALID_SERVICE_CONTROLThe requested control code is not valid, or it is unacceptable to the service.
ERROR_SERVICE_CANNOT_ACCEPT_CTRLThe requested control code cannot be sent to the service because the state of the service is SERVICE_STOPPED, SERVICE_START_PENDING, or SERVICE_STOP_PENDING.
ERROR_SERVICE_NOT_ACTIVEThe service has not been started.
ERROR_SERVICE_REQUEST_TIMEOUTThe process for the service was started, but it did not call StartServiceCtrlDispatcher, or the thread that called StartServiceCtrlDispatcher may be blocked in a control handler function.
ERROR_SHUTDOWN_IN_PROGRESSThe system is shutting down.
Remarks

The ControlService function asks the Service Control Manager (SCM) to send the requested control code to the service. The SCM sends the code if the service has specified that it will accept the code, and is in a state in which a control code can be sent to it.

The SCM processes service control notifications in a serial fashion — it will wait for one service to complete processing a service control notification before sending the next one. Because of this, a call to ControlService will block for 30 seconds if any service is busy handling a control code. If the busy service still has not returned from its handler function when the timeout expires, ControlService fails with ERROR_SERVICE_REQUEST_TIMEOUT.

To stop and start a service requires a security descriptor that allows you to do so. The default security descriptor allows the LocalSystem account, and members of the Administrators and Power Users groups to stop and start services. To change the security descriptor of a service, see Modifying the DACL for a Service.

The QueryServiceStatusEx function returns a SERVICE_STATUS_PROCESS structure whose dwCurrentState and dwControlsAccepted members indicate the current state and controls accepted by a running service. All running services accept the SERVICE_CONTROL_INTERROGATE control code by default. Drivers do not accept control codes other than SERVICE_CONTROL_STOP and SERVICE_CONTROL_INTERROGATE. Each service specifies the other control codes that it accepts when it calls the SetServiceStatus function to report its status. A service should always accept these codes when it is running, no matter what it is doing.

The following table shows the action of the SCM in each of the possible service states.

Service stateStopOther controls
STOPPED(c)(c)
STOP_PENDING(b)(b)
START_PENDING(a)(b)
RUNNING(a)(a)
CONTINUE_PENDING(a)(a)
PAUSE_PENDING(a)(a)
PAUSED(a)(a)

(a)
If the service accepts this control code, send the request to the service; otherwise, ControlService returns zero and GetLastError returns ERROR_INVALID_SERVICE_CONTROL.
(b)
The service is not in a state in which a control can be sent to it, so ControlService returns zero and GetLastError returns ERROR_SERVICE_CANNOT_ACCEPT_CTRL.
(c)
The service is not active, so ControlService returns zero and GetLastError returns ERROR_SERVICE_NOT_ACTIVE.

Example Code

For an example, see Sending Control Requests to a Service.

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.
Windows 编程之服务-2 四、自定义服务控制码 除了系统定义的五种控制码外(还有一种是:SERVICE_CONTROL_SHUTDOWN), 用户还可自定义控制码,其取值范围是128-255。用户可以通过控制面板中的服务 项向特定服务程序的控制处理函数发送控制码,程序员可以调用系统函数  ControlService 直接向服务程序的控制处理函数发送控制码。其函数原型如下: BOOL ControlServi 阅读详情

相关推荐

C# 驱动卸载 / UniSysDriver

如果你需要了解驱动如何加载,那么可以参考我的这篇文章 C# 驱动加载 / LoadSysDriver 总体两者的方法差异不大 public static bool UniSysDriver(string strServiceName) { IntPtr hSCManager = OpenSCManager(null, null, SC_MA

987

【原创】驱动卸载之ControlService函数

BOOL WINAPI ControlService( _In_ SC_HANDLE hService, _In_ DWORD dwControl, _Out_ LPSERVICE_STATUS lpServiceStatus ); 函数作用:给指定的服务发送一个控制码 参数: 1. hService: OpenService 或CreateService function返...

weixin_34054866的博客 269

深入解析车载以太网DoIP诊断:Wireshark实战TCP/UDS报文分析

本文深入解析车载以太网DoIP诊断,重点介绍如何利用Wireshark进行TCP/UDS报文实战分析。文章详细讲解了从以太网帧、IP帧、TCP段到DoIP协议及UDS服务的逐层拆解方法,并提供了使用Wireshark定位通信故障(如乱序、丢包、重传)的实用技巧,帮助工程师高效排查车载诊断网络问题。

c2d3e4f的博客 686

Windows下的服务控制管理器(SCM)

一、概要           服务管理器是用于管理系统服务的管理工具。一般常用于windows系统,使用这个工具你可以启动、停止服务;设置服务是自动、手动启动或禁用;查看某个服务的相关信息;设置服务以什么用户启动等等(一般包括了超级管理员用户、管理员用户和游客用户);设置用户注销,软件等。

xcbeyond|疯狂源自梦想,技术成就辉煌 2万+

Backblaze 2025全年硬盘故障率报告解读

作为长期追踪存储行业动态的科技博主,每年/季度Backblaze的Drive Stats报告都是我重点关注的核心内容——不同于厂商发布的实验室数据,Backblaze以近13年、数十万片企业级硬盘的真实运行数据为基础,其年化故障率(AFR)、寿命趋势等结论,直接反映了硬盘在严苛数据中心环境下的真实表现,无论是企业存储选型还是个人高端存储参考,都具备极高的实用价值。2025年末,Backblaze发布了第13年的年度收官报告,涵盖2025年Q4、全年及终身硬盘可靠性数据。

存储随笔 4047

智能手表竞品分析与市场调研报告

本报告旨在通过调研当前主流智能手表产品的功能特点、市场表现、用户反馈、定价策略等方面,辅助我司即将立项的Aurora Watch S1产品在功能定义、目标用户、定价区间、差异化竞争等方面做出科学决策。 调研范围包括国内外中端价位主流品牌(¥199~¥999),重点关注小米、华为、荣耀、Amazfit、Redmi、Haylou 等品牌的热销型号。

hoony123的博客 7万+

关于C++对 service 的控制

最简单的方式  ShellExecute( "net   stop   servicename ",...);  ShellExecute( "net   start   servicename ",...);  复杂的就是API函数  SC_HANDLE   OpenSCManager(      LPCTSTR   lpMachineName,       //   computer

xiunai78的专栏 1270

人形机器人电源系统硬件开发:从原理图设计到PCB布局的完整流程

人形机器人是“移动的智能终端”,其电源系统如同“心脏+血管”:既要为大脑(主控)、肌肉(电机)、感官(传感器)提供稳定能量,又要在有限体积内应对高动态负载(如跳跃时电机瞬间大电流)。本文聚焦“硬件开发”维度,覆盖从需求分析到PCB制板的完整流程,适合硬件工程师、机器人爱好者快速掌握工程实战方法。

AI天才研究院 2184

windows服务程序二

Windows 服务程序(二) </h1> <div class="clear"></div> <div class="postBody"> <div id="cnblogs_post_body" class="blogpost-body blogpost-body-html"> 服务...

宇之日记 622

uniapp 如何封装实现任意页面都能使用的全局弹窗

项目内容场景全局监听消息提示难点uniapp 无法全局挂载组件解决方案动态创建 DOM + 动态 Vue 实例优势跨页面 / 不依赖页面组件树 / 灵活调用如果你使用的是小程序平台,DOM 操作可能受限,需要用或方式兼容处理。想支持多个弹窗堆叠?你可以扩展,加个弹窗队列管理器。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 952

手把手教你学Simulink——基于Simulink的多用户MIMO系统仿真建模示例

多用户MIMO概述在多用户MIMO系统中,基站配备多个天线,可以同时与多个用户进行通信。利用空间复用技术,不同用户的信号被分配到不同的空间流上,从而实现频谱资源的高效利用。多用户MIMO的核心挑战包括信道估计、波束成形设计以及干扰管理。关键技术点波束成形:通过调整发射信号的相位和幅度,在特定方向上增强信号强度并减少干扰。信道估计:获取每个用户的信道状态信息(CSI),用于优化波束成形矩阵。调制与解调:选择合适的调制方式(如QPSK、16-QAM等)以适应不同用户的信道条件。干扰消除。

MHD0815的博客 277

Windows服务编写原理及探讨(四)

(四)一些问题的讨论   前面几章的内容都是服务的一些通用的编写原理,但里面隐含着一些问题,编写简单的服务时看不出来,但遇到复杂的应用就会出现一些问题,所以本章就是用来分析、解决这些问题的,适用于高级应用的开发人员。我这一章的内容都是经过实验得到的,很有实际意义。   我在第一章里面就说过,是由一个服务的主线程执行CtrlHandler函数,它将收到各种控制命令,但是真正处理命令,执行操作的是Se

hbb0b0的专栏 1052

西门子S7-1200PLC控制步进电机的组态编程和具体步骤

西门子S7-1200PLC控制步进电机的组态编程和具体步骤 硬件准备: 1) 一个S7-1214C DC/DC/DC,订货号:6ES7 214-1AG40-0XB0 2) 一个86系的步进电机+相应的驱动器 3) 一个20A的西门子24V电源(步进驱动器及plc电源) 4) Portal V15版本 组态及编程: 1) 创建一个验证项目,添加cpu( S7-1214C),双击“工艺对象”,选择“运动控制”的TO_PositioningAxis V6.0版本,如下图所示: 2) “确定”后,系统自动生成名

Robot_PLC_HMI_Automation 1万+

stf源码解读之ControlService-sendTwoWay(socket.io)双向通信

文章目录前言touchDown与installsendOneWay与sendTwoWay疑点TransactionService后台的消息发哪去了 前言 本文主要解读ControlService的sendTwoWay和sendOneWay的区别,sendTwoWay函数怎么实现双向通信的。 touchDown与install 我们看到 res/app/components/stf/screen/screen-directive.js有这样的调用方式 control.touchDown(nextSeq(),

harrain的博客 635

分享一个我自用的 Python 消息发送模块,支持邮件、钉钉、企业微信

🔥 分享一个我自用的 Python 消息发送模块,支持邮件、钉钉、企业微信

XiaoqiangClub的博客 484

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

[病毒分析]WinDBG实战教学(1)

WinDBG实战教学(1)一、初始任务二、开始分析三、分析代码四、WinDBG调试 这里的实例选自《恶意代码分析与实战》第十章实验一 大家可以在这里下载哦 点击下载—提取码:8189 实验工具: 1、WinDBG 2、IDA 3、Dependency Walker 一、初始任务 我们将下载好的文件放到指定位置 C:\Windows\System32 使用WinGDB 连接至虚拟机(CSDN中有很多关于WinDBG的初始教学,大家可以先看看) 出现下面的界面表示连接成功: 二、开始分析 第一步,我们使用D

网络安全知识分享 4145

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

c++ 驱动【加载,启动,停止,卸载】

驱动代码参考:https://blog.csdn.net/Simon798/article/details/103308039 exe 代码: #include <iostream> #include <Windows.h> using namespace std; // 安装驱动 BOOL installDvr(CONST WCHAR drvPath[50], CONST WCHAR serviceName[20]) { // 打开服务控制管理器数据库

LYSM 6081

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Android Studio求解Android SDK is up to date. Running Android Emulator hypervisor driver installer

由于发生错误 4294967201, StartService 失败。[SC] DeleteService 成功。看不懂错误是啥意思啊。

qq_51463650的博客 943

SERVICE_STATUS

SERVICE_STATUSThe SERVICE_STATUS structure contains information about a service. The ControlService, EnumDependentServices, EnumServicesStatus, and QueryServiceStatus functions use this structure to r

小发猫 2437

QueryServiceStatusEx

QueryServiceStatusExThe QueryServiceStatusEx function retrieves the current status of the specified service based on the specified information level.BOOL QueryServiceStatusEx( SC_HANDLE hService,

小发猫 2456

用delphi如何实现启动停止windows服务

function StartService(AServName: string): Boolean; //use WinSvc var SCManager, hService: SC_HANDLE; lpServiceArgVectors: PChar; begin SCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCE...

200

NT式驱动的卸载

NT式驱动的卸载 A、卸载驱动流程 B、内核函数DeleteService C、内核函数ControlService D、构建UnLoadSys函数 E、测试并查看调试信息 一、卸载驱动流程 1、用OpenSCManager函数打开 服务控制管理器,取得SCM句柄,如果返回NULL,则结束,否则继续2.//hSCM 2、用OpenService打开相应的服务,如果返回NULL,则结束,否则继续3.hSerVice 3、用ControlService停止驱动服务,如果返回NULL,只有重新启动才能,再动态加载

Windows内核学习笔记 298

服务编程——给一个服务发控制码

1、OpenSCManager 2、OpenService 3、Con

心之所向,身之所往 657

FoundationDB 8.0 版本发布全解析:API 800、Native CDC 与备份体系重构

本文基于 FoundationDB 开源仓库中的 [release-notes-800.rst](https://link.gitcode.com/i/aa5039b2211db3252d1d7b32685a9006) 官方发布说明,系统梳理 8.0(API Version 800)的核心变更:实验性多租户、元集群、静态加密等特性的移除与迁移规划,Native CDC、按范围 Bulk Dump/

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址