Delphi 判断某个系统服务是否存在及相关状态
记得use WinSvc; //-------------------------------------
// 获取某个系统服务的当前状态
//
// return status code if successful
// -1 if not
//
// return codes:
// SERVICE_STOPPED
// SERVICE_RUNNING
// SERVICE_PAUSED
//
// following return codes are used to indicate that the service is in the
// middle of getting to one of the above states:
// SERVICE_START_PENDING
// SERVICE_STOP_PENDING
// SERVICE_CONTINUE_PENDING
// SERVICE_PAUSE_PENDING
//
// sMachine:
// machine name, ie: \SERVER
// empty = local machine
//
//sService
// service name, ie: Alerter
//
function TFormConfig.ServiceGetStatus(sMachine, sService: string ): DWord;
var
//service control
//manager handle
schm,
//service handle
schs: SC_Handle;
//service status
ss: TServiceStatus;
//current service status
dwStat : DWord;
begin
dwStat := ;
//connect to the service
//control manager
schm := OpenSCManager(PChar(sMachine), Nil, SC_MANAGER_CONNECT);
//if successful...
if(schm > )then
begin
//open a handle to
//the specified service
schs := OpenService(schm, PChar(sService), SERVICE_QUERY_STATUS);
//if successful...
if(schs > )then
begin
//retrieve the current status
//of the specified service
if(QueryServiceStatus(schs, ss))then
begin
dwStat := ss.dwCurrentState;
end;
//close service handle
CloseServiceHandle(schs);
end; // close service control
// manager handle
CloseServiceHandle(schm);
end; Result := dwStat;
end; {判断某服务是否安装,未安装返回true,已安装返回false}
function TFormConfig.ServiceUninstalled(sMachine, sService : string ) : boolean;
begin
Result := = ServiceGetStatus(sMachine, sService);
end; {判断某服务是否启动,启动返回true,未启动返回false}
function TFormConfig.ServiceRunning(sMachine, sService : string ) : boolean;
begin
Result := SERVICE_RUNNING = ServiceGetStatus(sMachine, sService );
end; {判断某服务是否停止,停止返回true,未停止返回false}
function TFormConfig.ServiceStopped(sMachine, sService : string ) : boolean;
begin
Result := SERVICE_STOPPED = ServiceGetStatus(sMachine, sService );
end;
Delphi 判断某个系统服务是否存在及相关状态的更多相关文章
- delphi 判断是否出现滚动条
delphi 判断是否出现滚动条 if (GetWindowlong(Stringgrid1.Handle, GWL_STYLE) and WS_VSCROLL) <> 0 the ...
- Delphi 判断TImage是否为空及注意事项
Delphi 判断TImage是否为空:1)非空 Image1.Picture.Graphic <> nil2)为空 Image1.Picture.Graphic = nil注意不能用Im ...
- Delphi 判断按键状态
Delphi 判断按键状态 http://blog.sina.com.cn/s/blog_54da9cc001015di1.html (2012-04-05 14:22:50) 标签: 杂谈 分类: ...
- delphi判断MDI窗体的子窗体是否存在
转]delphi判断MDI窗体的子窗体是否存在//*************************************************************************** ...
- jquery设置、判断、获取input单选标签选中状态
1.设置某项单选input为选中状态: $("input[type='radio']").eq(1).attr('checked',true); ②也可设其属性checked为'c ...
- Delphi判断文件是否正在被使用(CreateFile也可以只是为了读取数据,而不是创建)
首先,我们先来认识下CreateFile函数,它的原型如下 HANDLE CreateFile( LPCTSTR lpFileName, //指向文件名的指针 DWORD dwDesired ...
- Delphi判断文件是否正在被使用
首先,我们先来认识下CreateFile函数,它的原型如下 HANDLE CreateFile( LPCTSTR lpFileName, //指向文件名的指针 DWORD dwDesired ...
- delphi判断线程是否正在运行
相关资料:http://www.delphitop.com/html/xiancheng/376.html unit Unit1; interface uses Winapi.Windows, Win ...
- delphi 判断一个数组的长度用 Length 还是 SizeOf ?
判断一个数组的长度用 Length 还是 SizeOf ?最近发现一些代码, 甚至有一些专家代码, 在遍历数组时所用的数组长度竟然是 SizeOf(arr); 这不合适! 如果是一维数组.且元素大小是 ...
随机推荐
- 使用Ueditor点击上传图片时显示延迟的问题
最近在做一个项目,需要用到Ueditor,但是在点击上传图片的时候,总是隔了4-5秒才显示文件框 查了一些资料,最后发现,只需在 修改:(1) dialog/images/image.js 把imag ...
- <Jmeter入门不放弃>之<3.两种常见录制脚本的方法>
关于录制,我想表达的是,并不要以为他很低端,解决需求才是王道,大家这里参考学习的时候,我就不在这里配截图了,因为需要你打开工具根据文档自己去找,才有印象,大家一定要启动JMeter!跟着理解操作 录制 ...
- subsequence 1
题目链接 题意:给你两个字符串都是数字,让你求第一个字符串的子序列中大于第二个字符串的个数. 思路:dp[i][j] 表示 str1的前i个,匹配 str2的前 j 个的种类数,那么 if(s[i] ...
- rabbitmq安装-1
原文地址和下载地址 原方地址: https://www.cnblogs.com/jiagoushi/p/9961388.html rabbitmq下载地址: https://github.com/ra ...
- 分布式系统理论基础1: 一致性、2PC和3PC
本文转自 https://www.cnblogs.com/bangerlee/p/5268485.html 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到 ...
- IDEA入门使用--二
*)IDEA安装和破解:https://www.cnblogs.com/jajian/p/7989032.html 这次我安装的是最新版2019的IDEA *)导入项目时,根据提示,一步步来.其 ...
- (转)Maven中的库(repository)详解 ---repository配置查找构件(如.jar)的远程库
转:https://blog.csdn.net/taiyangdao/article/details/52287856 Maven中的库(repository)是构件(artifact)的集合.构件以 ...
- python字符串比较大小
zfill函数 xs = ['] print (sorted(xs))
- NTFS文件系统
一.Volume和Cluster 卷(Volume)和簇(Cluster)是NTFS用来描述物理磁盘的单位. 卷之间是相对独立的,卷的概念其实就是分区(Partition). 簇的引入是为了方便处理不 ...
- vue/cli3引入cesium
vue/cli3引入cesium 一开始用了webpack结合vue引入vue:结果是各种bug,搞了半天.最后问了基友,发现vue脚手架这个·简单高效的方法,只需要几行代码就轻松地搞定啦! 方案一. ...