windows c++ 输出所有服务列表,并判断是否是开机启动项


#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

你可能感兴趣的:(c++,windows)