标签:begin 判断 end service SERVICE Delphi sService 某个 sMachine
1 记得use WinSvc; 2 3 //------------------------------------- 4 // 获取某个系统服务的当前状态 5 // 6 // return status code if successful 7 // -1 if not 8 // 9 // return codes: 10 // SERVICE_STOPPED 11 // SERVICE_RUNNING 12 // SERVICE_PAUSED 13 // 14 // following return codes are used to indicate that the service is in the 15 // middle of getting to one of the above states: 16 // SERVICE_START_PENDING 17 // SERVICE_STOP_PENDING 18 // SERVICE_CONTINUE_PENDING 19 // SERVICE_PAUSE_PENDING 20 // 21 // sMachine: 22 // machine name, ie: \SERVER 23 // empty = local machine 24 // 25 //sService 26 // service name, ie: Alerter 27 // 28 function TFormConfig.ServiceGetStatus(sMachine, sService: string ): DWord; 29 var 30 //service control 31 //manager handle 32 schm, 33 //service handle 34 schs: SC_Handle; 35 //service status 36 ss: TServiceStatus; 37 //current service status 38 dwStat : DWord; 39 begin 40 dwStat := 0; 41 //connect to the service 42 //control manager 43 schm := OpenSCManager(PChar(sMachine), Nil, SC_MANAGER_CONNECT); 44 //if successful... 45 if(schm > 0)then 46 begin 47 //open a handle to 48 //the specified service 49 schs := OpenService(schm, PChar(sService), SERVICE_QUERY_STATUS); 50 //if successful... 51 if(schs > 0)then 52 begin 53 //retrieve the current status 54 //of the specified service 55 if(QueryServiceStatus(schs, ss))then 56 begin 57 dwStat := ss.dwCurrentState; 58 end; 59 //close service handle 60 CloseServiceHandle(schs); 61 end; 62 63 // close service control 64 // manager handle 65 CloseServiceHandle(schm); 66 end; 67 68 Result := dwStat; 69 end; 70 71 {判断某服务是否安装,未安装返回true,已安装返回false} 72 function TFormConfig.ServiceUninstalled(sMachine, sService : string ) : boolean; 73 begin 74 Result := 0 = ServiceGetStatus(sMachine, sService); 75 end; 76 77 {判断某服务是否启动,启动返回true,未启动返回false} 78 function TFormConfig.ServiceRunning(sMachine, sService : string ) : boolean; 79 begin 80 Result := SERVICE_RUNNING = ServiceGetStatus(sMachine, sService ); 81 end; 82 83 {判断某服务是否停止,停止返回true,未停止返回false} 84 function TFormConfig.ServiceStopped(sMachine, sService : string ) : boolean; 85 begin 86 Result := SERVICE_STOPPED = ServiceGetStatus(sMachine, sService ); 87 end;
标签:begin,判断,end,service,SERVICE,Delphi,sService,某个,sMachine 来源: https://www.cnblogs.com/Thenext/p/16581982.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。