永发信息网

C语言高手进来看看啊,遍历进程不知道哪里出错了。

答案:2  悬赏:80  手机版
解决时间 2021-02-08 04:35
  • 提问者网友:做自己de王妃
  • 2021-02-07 09:01
#include
#include
#include
void main()
{
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
HANDLE hProcessSnap;
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hProcessSnap == INVALID_HANDLE_VALUE)
{
exit(1);
} while(Process32First(hProcessSnap,&pe32));
{
printf("进程名:%s\n",pe32.szExeFile);

Process32Next(hProcessSnap,&pe32);
}
CloseHandle(hProcessSnap);
}
最佳答案
  • 五星知识达人网友:胯下狙击手
  • 2021-02-07 10:23
while(Process32First(hProcessSnap,&pe32));
{
printf("进程名:%s\n",pe32.szExeFile);

Process32Next(hProcessSnap,&pe32);
}
错在这个while,Process32First函数调用一次就可以了,后面的循环用Process32Next的返回值遍历来完成
全部回答
  • 1楼网友:玩世
  • 2021-02-07 11:29
#include <tlhelp32.h> #include <psapi.h> #pragma comment(lib, "psapi.lib") bool getprocesslist() { bool bresult = false; handle hsnap = createtoolhelp32snapshot(th32cs_snapprocess, 0); if ( hsnap == invalid_handle_value ) return false; int idx = 0; cstring strid; handle hprocess = null; processentry32 info = {0}; info.dwsize = sizeof(processentry32); bool bret = process32first(hsnap, &info); while(bret) { idx = m_tasklist.insertitem(m_tasklist.getitemcount(), _t("")); m_tasklist.setitemtext(idx, 0, info.szexefile); strid.empty(); strid.format(_t("%d"), info.th32processid); m_tasklist.setitemtext(idx, 1, strid); hprocess = openprocess(process_query_information | process_vm_read, false, info.th32processid); if (hprocess) { tchar szpath[max_path] = {0}; getmodulefilenameex(hprocess, null, szpath, max_path); m_tasklist.setitemtext(idx, 2, szpath); } bret = process32next(hsnap, &info); } return true; } 用快照行吧,这个函数可以满足你
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯