win10打印所有进程
阅读原文时间:2023年07月11日阅读:2

#include
#include
#include

#include
#include // Never include win32 heads before window.h

bool printAllProcess(std::map &_mapProcess, bool is_print = true)
{
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);

HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS\_SNAPPROCESS, 0);  
if (hProcessSnap == INVALID\_HANDLE\_VALUE) {  
    std::cout << "CreateToolhelp32Snapshot Error!" << std::endl;;  
    return false;  
}

BOOL bResult = Process32First(hProcessSnap, &pe32);

int num(0);

while (bResult)  
{  
    std::wstring name = pe32.szExeFile;  
    int id = pe32.th32ProcessID;  
    if (is\_print)  
    {  
        std::cout << "\[" << ++num << "\]: " << "--ProcessID:" << id;  
        std::wcout << "--Process Name:" << name << std::endl;  
    }  
    \_mapProcess.insert(std::pair<std::wstring, int>(name, id));  
    bResult = Process32Next(hProcessSnap, &pe32);  
}

CloseHandle(hProcessSnap);  
return true;  

}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器