#include
#include
#include
int main() {
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
if (hSCManager == NULL) {
std::cout << "无法打开服务控制管理器。错误代码:" << GetLastError() << std::endl;
return 1;
}
DWORD dwBytesNeeded;
DWORD dwServicesReturned;
DWORD dwResumeHandle = 0;
// 获取服务状态信息所需的缓冲区大小
EnumServicesStatusEx(hSCManager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, NULL, 0, &dwBytesNeeded, &dwServicesReturned, &dwResumeHandle, NULL);
// 分配缓冲区
LPENUM_SERVICE_STATUS_PROCESS lpServices = (LPENUM_SERVICE_STATUS_PROCESS) new BYTE[dwBytesNeeded];
// 获取服务状态信息
if (!EnumServicesStatusEx(hSCManager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ST