1. BOOL WINAPI ControlService(
  2. _In_ SC_HANDLE hService,
  3. _In_ DWORD dwControl,
  4. _Out_ LPSERVICE_STATUS lpServiceStatus
  5. );
函数作用:给指定的服务发送一个控制码
参数:
1. hService: OpenService 或CreateService function返回的服务句柄;
2. dwControl:要发送的控制码,控制码可以是下列系统定义的控制码;也可以是用户自定义的控制码,范围是128-255,需要有SERVICE_USER_DEFINED_CONTROL权限。
Control code Meaning
SERVICE_CONTROL_CONTINUE
0x00000003

Notifies a paused service that it should resume. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.

(恢复服务,需要SERVICE_PAUSE_CONTINUE权限)

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.

Note that this control is not generally useful as the SCM is aware of the current state of the service.

(向SCM报告服务的当前状态信息,需要有SERVICE_INTERROGATE权限)

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.

(网络绑定相关,已废弃

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.

(网络绑定相关,已废弃

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.

(网络绑定相关,已废弃

SERVICE_CONTROL_NETBINDREMOVE
0x00000008

Notifies a network service 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.

(网络绑定相关,已废弃

SERVICE_CONTROL_PARAMCHANGE
0x00000006

Notifies a service that its startup parameters have changed. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.

(服务启动参数已经改变,需要有SERVICE_PAUSE_CONTINUE权限)

SERVICE_CONTROL_PAUSE
0x00000002

Notifies a service that it should pause. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.

(暂停服务,需要有SERVICE_PAUSE_CONTINUE权限)

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.

(停止服务,需要有SERVICE_STOP权限)

3. lpServiceStatus:返回值,一个指向存储服务最新状态的结构体ServiceStatus,返回的服务信息来自SCM中最近的服务状态报告。
只有当ControlService返回以下的错误代码:NO_ERROR, ERROR_INVALID_SERVICE_CONTROL, ERROR_SERVICE_CANNOT_ACCEPT_CTRL, or ERROR_SERVICE_NOT_ACTIVE,
SCM才会填充结构体ServiceStatus。
 
返回值:
成功,返回非0;
失败,返回0,错误码使用GetLastError获得;
Return code Description
ERROR_ACCESS_DENIED

The handle does not have the required access right.

ERROR_DEPENDENT_SERVICES_RUNNING

The service cannot be stopped because other running services are dependent on it.

ERROR_INVALID_HANDLE

The specified handle was not obtained using CreateService or OpenService, or the handle is no longer valid.

ERROR_INVALID_PARAMETER

The requested control code is undefined.

ERROR_INVALID_SERVICE_CONTROL

The requested control code is not valid, or it is unacceptable to the service.

ERROR_SERVICE_CANNOT_ACCEPT_CTRL

The 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_ACTIVE

The service has not been started.

ERROR_SERVICE_REQUEST_TIMEOUT

The 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_PROGRESS

The system is shutting down.

说明:
(1)ControlService函数要求服务控制管理器(SCM)向服务发送请求的控制代码。SCM发送的前提是服务已经指定要接收控制码,或服务处于控制码可以发送给它的一个状态。
(2)SCM是以串行的方式处理服务控制通知——它会等待服务完成一个服务控制通知的处理,才发送下一个通知。所以如果任何服务正忙于处理一个控制码,ControlService的一个调用将会暂停30s的时间(这是一个超时时间),如果超时时间一过但处理还没完成,那么函数将返回一个ERROR_SERVICE_REQUEST_TIMEOUT。
(3)其他:

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 state Stop Other 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.

本文链接:http://www.cnblogs.com/cposture/p/4717546.html

【原创】驱动卸载之ControlService函数的更多相关文章

  1. hook键盘驱动中的分发函数实现键盘输入数据的拦截

    我自己在看<寒江独钓>这本书的时候,书中除了给出了利用过滤的方式来拦截键盘数据之外,也提到了另外一种方法,就是hook键盘分发函数,将它替换成我们自己的,然后再自己的分发函数中获取这个数据 ...

  2. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数017·point点函数

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数017·point点函数 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“p ...

  3. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数015,vector矢量

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数015,vector矢量 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“p ...

  4. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数016,xld,xld轮廓

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数016,xld,xld轮廓 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“ ...

  5. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数014,tuple,元组

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数014,tuple,元组 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“p ...

  6. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数013,shape模型

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数013,shape模型 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“pr ...

  7. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数012,polygon,多边形

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数012,polygon,多边形 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换 ...

  8. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数011,ocr,字符识别

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数011,ocr,字符识别 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“p ...

  9. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数010,obj,对象管理

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数010,obj,对象管理 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“p ...

随机推荐

  1. 安装rabbtimq CentOS 7

    朋友们 今天安装rabbtimq  在安装完以后就是一直报错.一直启动不起来了.最后看到别人写到.centos 7  与 centos 6.下载的rabbitmq是不一样的. https://dl.b ...

  2. usb 枚举流程

    Linux-USB总线驱动分析 如下图所示,以windows为例,我们插上一个没有USB设备驱动的USB,就会提示你安装驱动程序 为什么一插上就有会提示信息? 是因为windows自带了USB总线驱动 ...

  3. vue中集成pdfjs自定义分页

    <template> <div id="div_read_area_scrool" class="no-scrollbar--x" :styl ...

  4. Exp9 Web安全基础

    Exp9 Web安全基础 20154305 齐帅 一.实验要求 本实践的目标理解常用网络攻击技术的基本原理. Webgoat实践下相关实验: [目录] [第一部分 WebGoat 8.0] 1.Web ...

  5. opencv2.4.13+python2.7学习笔记--使用 knn对手写数字OCR

    阅读对象:熟悉knn.了解opencv和python. 1.knn理论介绍:算法学习笔记:knn理论介绍 2. opencv中knn函数 路径:opencv\sources\modules\ml\in ...

  6. template模板的使用方法

    模板 WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用. 定义模板 使用name属性,作为模板的名字.然后在<template/>内定义代码片段 使用模 ...

  7. pm2模块编写入门

    PM2 模块 PM2模块是通过PM2来安装和管理,代码可以托管在NPM中.任何人都可以创建和发布一个PM2模块,可以是日志模块.http代理模块.负载均衡模块.DNS服务器模块或任何类型的实用程序. ...

  8. Shell变量类型和运算符-2

  9. 学习Axure RP原型设计

    1 概述 原型设计是应用开发设计的第一要素.好的原型设计不仅可以起到沟通的作用,而且对客户而言应用程序拥有更直观的体现.原型设计通过内容和结构展示以及界面布局编排,实现在开发前期用户与产品进行交互.提 ...

  10. 搞Java的年薪 40W 是什么水平?

    既然楼主提到年薪40w,那我们看看什么公司,什么级别可以给到,再看看要求.阿里是Java大厂,所以可以参考阿里的标准. 阿里一般是16薪水,所以就是税前2.5w,在阿里应该是P6就可以达到,而对P6的 ...