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); 这不合适! 如果是一维数组.且元素大小是 ...
随机推荐
- PHP chdir() 函数
实例 改变当前的目录: <?php// Get current directoryecho getcwd() . "<br>"; // Change direct ...
- UNP学习第八章udp
一.基本UDP套接口编程 #include <sys/socket.h> ssize_t recvfrom(int sockfd, void *buff, size_t nbytes, i ...
- Comet OJ 茶颜悦色 线段树+扫描线(矩形覆盖最多点+优化)
题目:https://www.cometoj.com/contest/59/problem/D?problem_id=2713 题意:给你一个正方形,然后给你n个点,这个正方形能随意放哪,要求那个正方 ...
- Cent OS 7下安装 mongodb
1.下载MongoDB 安装包 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.8.tgz 2.解压并安装 .tgz 3. ...
- What is the difference between UserControl, WebControl, RenderedControl and CompositeControl?
What is the difference between UserControl, WebControl, RenderedControl and CompositeControl? UserCo ...
- 详解代理自动配置 PAC
转自知乎 最近一直在做跨域中华局域网的工作,了解了很多代理知识和基础概念,很零散,也很细碎.希望通过一段时间的学习,能够自由地穿梭在国际互联网和中华局域网之间.后续会写一系列文章记录我了解到的知识点, ...
- 常用命令--awk
awk '{ BEGIN{stat1} BEGIN{stat2} pattern1{action1} pattern2{action2} ... patternn{actionn} {默认动作,无条件 ...
- Scala 槽点 - require
require def this(name: String, age: Int) = { this() require(name != null && !name.isEmpty, & ...
- 【DRP】採用dom4j完毕XML文件导入数据库
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/lantingxv_jing/article/details/37762523 xml文件在如 ...
- SpringBoot开发详解(五)--Controller接收参数以及参数校验
原文链接:http://blog.csdn.net/qq_31001665 如有侵权,请联系博主删除博客,谢谢 Controller 中注解使用 接受参数的几种传输方式以及几种注解: 在上一篇中,我 ...