获取进程信息

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 }

转载于:https://www.cnblogs.com/spinsoft/archive/2012/05/03/2480574.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值