1 // EmunProcess.cpp : 定义控制台应用程序的入口点。
2 ///////////////////////////////////////////////////////////////////////////////
3 ///
4 /// Copyright (c) 2012 - <company name here>
5 ///
6 /// Original filename: EmunProcess.cpp
7 /// Project : EmunProcess
8 /// Date of creation : 2012-05-03
9 /// Author(s) : <xielechuan>
10 ///
11 /// Purpose : <Get the Process Information>
12 ///
13 /// Revisions:
14 /// 0000 [2012-05-02] Initial revision.
15 ///
16 ///////////////////////////////////////////////////////////////////////////////
17
18 #include "stdafx.h"
19 #include <Windows.h>
20 #include <tlhelp32.h>
21 #include <iostream>
22 using namespace std;
23
24 int _tmain(int argc, _TCHAR* argv[])
25 {
26 HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
27 if (hProcessSnap == INVALID_HANDLE_VALUE)
28 {
29 cout<<"CreateToolHelp32Snap Failed~~"<<endl;
30 return -1;
31 }
32
33 PROCESSENTRY32 pe32;
34 pe32.dwSize = sizeof(PROCESSENTRY32);
35 //遍历进程快照,显示进程的信息
36 BOOL bMore = Process32First(hProcessSnap,&pe32);
37 int i =0;
38 cout<<"PID\t"<<"线程数\t"<<"进程名称"<<endl;
39 while (bMore)
40 {
41 bMore = Process32Next(hProcessSnap,&pe32);
42 cout<<pe32.th32ProcessID<<"\t";
43 cout<<pe32.cntThreads<<"\t";
44 cout<<pe32.szExeFile<<endl;
45 i++;
46 }
47 //清除snapshot对象
48 CloseHandle(hProcessSnap);
49 cout<<"进程总数为"<<i<<endl;
50 system("pause");
51 return 0;
52 }