zoukankan      html  css  js  c++  java
  • 获取进程信息

    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 }

  • 相关阅读:
    exploded archive 和packaged archive 区别
    MyEclipse6.5使用设置技巧及快捷键
    本机上设置域名解析
    Cookie的生命周期问题
    简单的函数柯里化
    cookie操作
    自定义事件
    解耦应用逻辑/事件处理程序
    dragdrop + 自定义事件
    在窃取函数中用作用域安全的构造函数
  • 原文地址:https://www.cnblogs.com/spinsoft/p/2480574.html
Copyright © 2011-2022 走看看