您的位置:首页 > 其它

获取进程信息

2012-05-03 14:29 155 查看
// EmunProcess.cpp : 定义控制台应用程序的入口点。
///////////////////////////////////////////////////////////////////////////////
///
/// Copyright (c) 2012 - <company name here>
///
/// Original filename: EmunProcess.cpp
/// Project          : EmunProcess
/// Date of creation : 2012-05-03
/// Author(s)        : <xielechuan>
///
/// Purpose          : <Get the Process Information>
///
/// Revisions:
///  0000 [2012-05-02] Initial revision.
///
///////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <Windows.h>
#include <tlhelp32.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
cout<<"CreateToolHelp32Snap Failed~~"<<endl;
return -1;
}

PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
//遍历进程快照,显示进程的信息
BOOL bMore = Process32First(hProcessSnap,&pe32);
int i =0;
cout<<"PID\t"<<"线程数\t"<<"进程名称"<<endl;
while (bMore)
{
bMore = Process32Next(hProcessSnap,&pe32);
cout<<pe32.th32ProcessID<<"\t";
cout<<pe32.cntThreads<<"\t";
cout<<pe32.szExeFile<<endl;
i++;
}
//清除snapshot对象
CloseHandle(hProcessSnap);
cout<<"进程总数为"<<i<<endl;
system("pause");
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: