C/C++遍历进程和进程ID的小工具

180it 2020-10-10 PM 1909℃ 0条

include <Windows.h>

include <stdio.h>

include <TlHelp32.h>

int main()
{

HANDLE hProceessnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProceessnap == INVALID_HANDLE_VALUE)
{
    printf_s("创建进行快照失败\n");
    return -1;
}
else
{
    PROCESSENTRY32 pe32;
    pe32.dwSize = sizeof(pe32);
    BOOL hProcess = Process32First(hProceessnap, &pe32);
    char buff[1024];
    while (hProcess)
    {
        wsprintf(buff, "进程名:%s--------------------进程ID:%d", pe32.szExeFile, pe32.th32ParentProcessID);
        printf_s("%s\n", buff);
        memset(buff, 0x00, 1024);
        hProcess = Process32Next(hProceessnap, &pe32);
    }
}
CloseHandle(hProceessnap);

return 0;

}

来源:https://blog.csdn.net/qq78442761/article/details/54646010

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

C/C++遍历进程和进程ID的小工具