记得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 判断某个系统服务是否存在及相关状态的更多相关文章

  1. delphi 判断是否出现滚动条

    delphi 判断是否出现滚动条     if (GetWindowlong(Stringgrid1.Handle, GWL_STYLE) and WS_VSCROLL) <> 0 the ...

  2. Delphi 判断TImage是否为空及注意事项

    Delphi 判断TImage是否为空:1)非空 Image1.Picture.Graphic <> nil2)为空 Image1.Picture.Graphic = nil注意不能用Im ...

  3. Delphi 判断按键状态

    Delphi 判断按键状态 http://blog.sina.com.cn/s/blog_54da9cc001015di1.html (2012-04-05 14:22:50) 标签: 杂谈 分类:  ...

  4. delphi判断MDI窗体的子窗体是否存在

    转]delphi判断MDI窗体的子窗体是否存在//*************************************************************************** ...

  5. jquery设置、判断、获取input单选标签选中状态

    1.设置某项单选input为选中状态: $("input[type='radio']").eq(1).attr('checked',true); ②也可设其属性checked为'c ...

  6. Delphi判断文件是否正在被使用(CreateFile也可以只是为了读取数据,而不是创建)

    首先,我们先来认识下CreateFile函数,它的原型如下   HANDLE CreateFile( LPCTSTR lpFileName,    //指向文件名的指针 DWORD dwDesired ...

  7. Delphi判断文件是否正在被使用

    首先,我们先来认识下CreateFile函数,它的原型如下   HANDLE CreateFile( LPCTSTR lpFileName,    //指向文件名的指针 DWORD dwDesired ...

  8. delphi判断线程是否正在运行

    相关资料:http://www.delphitop.com/html/xiancheng/376.html unit Unit1; interface uses Winapi.Windows, Win ...

  9. delphi 判断一个数组的长度用 Length 还是 SizeOf ?

    判断一个数组的长度用 Length 还是 SizeOf ?最近发现一些代码, 甚至有一些专家代码, 在遍历数组时所用的数组长度竟然是 SizeOf(arr); 这不合适! 如果是一维数组.且元素大小是 ...

随机推荐

  1. Database基础(六):实现MySQL读写分离、MySQL性能调优

    一.实现MySQL读写分离 目标: 本案例要求配置2台MySQL服务器+1台代理服务器,实现MySQL代理的读写分离: 用户只需要访问MySQL代理服务器,而实际的SQL查询.写入操作交给后台的2台M ...

  2. 探索Redis设计与实现3:Redis内部数据结构详解——sds

    本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...

  3. Android的Context && 安卓常用系统服务(当前运行包名/当前网络状态和开关网络/音频服务/马达服务) (转)

    转:http://blog.csdn.net/zhandoushi1982/article/details/8501773 Context字面意思上下文,位于framework 的android.co ...

  4. (转)使用OpenGL显示图像(二)定义Shapes

    定义形状 编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/shapes.html 在一个OpenGL ES Vi ...

  5. zju1610Count the Colors

    ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting s ...

  6. Redis入门很简单之二【常见操作命令】

    Redis入门很简单之二[常见操作命令] 博客分类: NoSQL/Redis/MongoDB redisnosql缓存  Redis提供了丰富的命令,允许我们连接客户端对其进行直接操作.这里简单介绍一 ...

  7. C++——运行时类型识别RTTI

    1.实现方式 typeid运算符,返回表达式的类型 dynamic_cast运算符,基类的指针或引用安全地转换成派生类的指针或引用 2.适用于:使用基类的指针或引用执行派生类的操作,且该操作不是虚函数 ...

  8. 解决(Oracle)ORA-12528: TNS: 监听程序: 所有适用例程都无法建立新连接 问题

    解决(Oracle)ORA-12528: TNS: 监听程序: 所有适用例程都无法建立新连接 问题通过在CMD下用lsnrctl status 查看出的问题:发现BLOCKEDORACLE启动步骤:s ...

  9. A1082 Read Number in Chinese (25 分)

    1082 Read Number in Chinese (25 分)   Given an integer with no more than 9 digits, you are supposed t ...

  10. UVA1595_Symmetry

    给出平面上n个点,问你能不能找到一个竖线让他们对称 这道题后面发现真的不难,又不止一种方法 我当时写的很挫,死脑筋的就找一个点的对称点存不存在,用结构体存点信息,在排序用find找,,然后不知道一堆w ...