C++语言:
Codee#11958
01
#include <Windows.h>
02 #include <TlHelp32.h>
03 #include <iostream>
04
05 int main( int argc , char * argv [] )
06 {
07 PROCESSENTRY32 pe32;
08
09 pe32 . dwSize = sizeof( pe32 );
10
11 // 给所有可见进程拍快照
12 HANDLE hProcessSnap = :: CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS , 0 );
13 if ( hProcessSnap == INVALID_HANDLE_VALUE )
14 {
15 std :: cout << "CreateToolhelp32Snapshot Fail! /n ";
16 return - 1;
17 }
18
19 // 开始遍历进程快照
20 if ( ! :: Process32First( hProcessSnap , & pe32 ) )
21 {
22 std :: cout << "Process32First失败!" << std :: endl;
23 return - 1;
24 }
25
26 int counter = 0;
27 do
28 {
29 // 打印进程列表
30 std :: wcout << "[" << ++ counter << "] /t 进程名: /t/t " << pe32 . szExeFile << std :: endl;
31 std :: cout << " /t 进程ID号: /t " << pe32 . th32ProcessID << std :: endl << std :: endl;
32 } while ( :: Process32Next( hProcessSnap , & pe32 ) );
33
34 :: CloseHandle( hProcessSnap ); // 关闭句柄
35
36 return 0;
37 }
02 #include <TlHelp32.h>
03 #include <iostream>
04
05 int main( int argc , char * argv [] )
06 {
07 PROCESSENTRY32 pe32;
08
09 pe32 . dwSize = sizeof( pe32 );
10
11 // 给所有可见进程拍快照
12 HANDLE hProcessSnap = :: CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS , 0 );
13 if ( hProcessSnap == INVALID_HANDLE_VALUE )
14 {
15 std :: cout << "CreateToolhelp32Snapshot Fail! /n ";
16 return - 1;
17 }
18
19 // 开始遍历进程快照
20 if ( ! :: Process32First( hProcessSnap , & pe32 ) )
21 {
22 std :: cout << "Process32First失败!" << std :: endl;
23 return - 1;
24 }
25
26 int counter = 0;
27 do
28 {
29 // 打印进程列表
30 std :: wcout << "[" << ++ counter << "] /t 进程名: /t/t " << pe32 . szExeFile << std :: endl;
31 std :: cout << " /t 进程ID号: /t " << pe32 . th32ProcessID << std :: endl << std :: endl;
32 } while ( :: Process32Next( hProcessSnap , & pe32 ) );
33
34 :: CloseHandle( hProcessSnap ); // 关闭句柄
35
36 return 0;
37 }