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); 这不合适! 如果是一维数组.且元素大小是 ...
随机推荐
- 原生js和jquery
$(document).ready(function() {//jquery的写法 }); (function () { //原生js的写法 })();
- ansible_playbook语法中的循环语句归纳
种类一.标准循环添加多个用户 - name: add several users user: name={{ item }} state=present groups=wheel with_items ...
- linux基础知识-常用命令
ifconfig :查看当前ip hostname:查看主机名 vim /etc/hosts:修改地址映射 service iptables status : 查看防火墙状态 chkconfig ip ...
- Xcode 5 下的单元测试
新版Xcode 5和Server发布以后,apple对单元测试的支持是越来越好了.从这一点看出apple对单元测试的也是越来越重视了. 这篇Blog就简单的介绍这集成化测试功能. Server更新后是 ...
- 升级到Xcode 5.1和iOS 7遇到的各种问题及解决办法汇总:
<iOS 企业证书部署无效的问题>:http://t.cn/8s7ILWZ <clipsToBounds 属性默认值变了>:http://weibo.com/165881473 ...
- 2018icpc南京/gym101981 G Pyramid 找规律
题意: 数一个金字塔里面有多少个正三角形. 题解: ans[n]=n*(n-1)*(n-2)*(n-3)/24 #include<bits/stdc++.h> using namespac ...
- 原生写一个一键获取所有DOM元素的方法
一天挺一个朋友去面试要做一个获取dom元素到数组中 主要用到一个递归算法,通过节点的childNodes属性--代码如下: function getAllNode() { var nodes = do ...
- 54、salesforce学习笔记(一)
Decimal priceDecimal = -4.50; System.debug('小数的绝对值为:'+priceDecimal.abs()); System.debug('priceDecima ...
- A + B Problem II HDU - 1002
非常简单的大数加法,因为不会Java只能手写大数加法了;博客存一下以后回来看看 #include<bits/stdc++.h> using namespace std; +; char A ...
- ldap认证服务的搭建
1. Ldap服务介绍 LDAP 全称轻量级目录访问协议(英文:Lightweight Directory Access Protocol),是一个运行在 TCP/IP 上的目录访问协议.目录是一个特 ...