c++检测windows服务程序状态
来源:互联网 发布:淘宝聚划算报名要求 编辑:程序博客网 时间:2024/06/05 12:07
代码如下:
TCHAR szSvcName[] = _TEXT("test");SC_HANDLE schSCManager;SC_HANDLE schService;SERVICE_STATUS_PROCESS ssStatus;DWORD dwOldCheckPoint;DWORD dwStartTickCount;DWORD dwWaitTime;DWORD dwBytesNeeded;// Get a handle to the SCM database.schSCManager = OpenSCManager(NULL, // local computerNULL, // ServicesActive databaseSC_MANAGER_ALL_ACCESS); // full access rightsif (NULL == schSCManager){printf("OpenSCManager failed (%d)\n", GetLastError());}// Get a handle to the service.schService = OpenService(schSCManager, // SCM databaseszSvcName, // name of service SERVICE_QUERY_STATUS |SERVICE_ENUMERATE_DEPENDENTS); // full accessif (schService == NULL){printf("OpenService failed (%d)\n", GetLastError());CloseServiceHandle(schSCManager);} // Check the status in case the service is not stopped.if (!QueryServiceStatusEx(schService, // handle to serviceSC_STATUS_PROCESS_INFO, // information level(LPBYTE) &ssStatus, // address of structuresizeof(SERVICE_STATUS_PROCESS), // size of structure&dwBytesNeeded ) ) // size needed if buffer is too small{printf("QueryServiceStatusEx failed (%d)\n", GetLastError());CloseServiceHandle(schService);CloseServiceHandle(schSCManager);}else{// Check if the service is already running. It would be possible// to stop the service here, but for simplicity this example just returns.printf("Service status: ");switch(ssStatus.dwCurrentState){case SERVICE_STOPPED:case SERVICE_STOP_PENDING:printf("Stop");break;case SERVICE_PAUSED:case SERVICE_PAUSE_PENDING:printf("Pause");break;case SERVICE_CONTINUE_PENDING:case SERVICE_RUNNING:case SERVICE_START_PENDING:printf("Running");break;}printf("\n");}
文章转载自:http://www.dotblogs.com.tw/alonstar/archive/2011/06/30/c_plus_windows_service.aspx
0 0
- c++检测windows服务程序状态
- C语言编写Windows服务程序。
- 用C语言编写Windows服务程序
- C编写Windows服务程序详细介绍
- 用 C 语言编写 Windows 服务程序
- 用C语言编写Windows服务程序
- C编写Windows服务程序详细介绍
- C语言书写Windows服务程序
- C语言编写Windows服务程序
- C#Windows服务程序的快速开发
- C#Windows服务程序开发实例浅析
- C#Windows服务程序开发实例浅析
- 用C/C++创建windows服务程序
- C#Windows服务程序开发实例浅析
- C#Windows服务程序开发实例浅析
- 用C/C++创建windows服务程序
- 用C编写Windows服务程序
- 用C/C++创建windows服务程序
- InitCommonControlsex
- C#设计模式(七)装饰者模式
- DES 加密解密
- 【转自loveifa】PHP 获取邮箱未读邮件的方法 根据receivemail改编而来,已解决乱码,编码问题
- 1592 - Database
- c++检测windows服务程序状态
- Android ImageView实现圆角,圆形图片
- POJ 1995 Raising Modulo Numbers (快速幂模板)
- ssh上传下载 自己整理的。
- 我对Laravel ThinkPHP Yii symfony2 CI cakephp 的看法
- 学习笔记----伸展树
- 冬令营第十三天
- PHP Extension的开发基础
- AfxSocketInit