#include <iostream>
#include <Windows.h>
using namespace std;
int main(int argc, char** argv)
{
SC_HANDLE hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
if(NULL == hScm)
{
return -1;
}
DWORD dwSize = 0;
DWORD dwServiceNum = 0;
EnumServicesStatusEx(hScm, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
NULL, 0, &dwSize, &dwServiceNum, NULL, NULL);
LPENUM_SERVICE_STATUS_PROCESS pcBuff = NULL;
pcBuff = (LPENUM_SERVICE_STATUS_PROCESS)malloc(dwSize);
memset(pcBuff, 0, dwSize);
EnumServicesStatusEx(hScm, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
(LPBYTE)pcBuff, dwSize, &dwSize, &dwServiceNum, NULL, NULL);
//遍历信息
for (DWORD i=0;i<dwServiceNum;i++)
{
cout << pcBuff[i].lpServiceName << endl << pcBuff[i].lpDisplayName << endl << pcBuff[i].ServiceStatusProcess.dwCurrentState << endl;
}
getchar();
CloseServiceHandle(hScm);
return 0;
}
windows下遍历当前任务管理器中的服务的列表
最新推荐文章于 2021-12-28 15:11:52 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)