Skip to content

Commit 652f881

Browse files
authored
获取所有进程
1 parent 07e7002 commit 652f881

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
#include <windows.h>
2-
#include <tlhelp32.h> //声明快照头文件
2+
#include <tlhelp32.h> //声明快照头文件
33
#include <iostream>
44
using namespace std;
55

66
int main() {
77
PROCESSENTRY32 pe32;
88
pe32.dwSize = sizeof(pe32);
99

10-
HANDLE hprocesssnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //当前所有进程快照
11-
if (hprocesssnap == INVALID_HANDLE_VALUE) {
12-
cout << "CreateToolhelp32Snapshot失败" << endl;
10+
HANDLE hpsnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //当前所有进程快照
11+
if (hpsnap == INVALID_HANDLE_VALUE) {
12+
cout << "CreateToolhelp32Snapshot失败" << endl;
1313
return -1;
1414
}
1515

16-
BOOL bnext = ::Process32First(hprocesssnap, &pe32); //遍历当前进程快照
16+
BOOL bnext = ::Process32First(hpsnap, &pe32); //遍历当前进程快照
1717
while (bnext) {
18-
cout << "进程名称:" << pe32.szExeFile << endl;
19-
cout << "进程ID号:" << pe32.th32ProcessID << endl << endl;
20-
bnext = ::Process32Next(hprocesssnap, &pe32);
18+
cout << "进程名称:" << pe32.szExeFile << endl;
19+
cout << "进程ID号:" << pe32.th32ProcessID << endl << endl;
20+
bnext = ::Process32Next(hpsnap, &pe32);
2121
}
2222

23-
::CloseHandle(hprocesssnap);
23+
::CloseHandle(hpsnap);
2424

2525
return 0;
26-
}
26+
}

0 commit comments

Comments
 (0)