现在的位置: 首页 > 综合 > 正文

进程列表

2013年10月12日 ⁄ 综合 ⁄ 共 1145字 ⁄ 字号 评论关闭

 进程列表

作者:Ackarlix

 

代码:

#include "stdafx.h"
#include <windows.h>
#include <tlhelp32.h>
#include <fstream.h>

int main(int argc, char* argv[])
{

 ofstream outfile("ProcessList.txt");
 PROCESSENTRY32 pe32;
 pe32.dwSize = sizeof(pe32);

 HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 if (hProcessSnap == INVALID_HANDLE_VALUE)
 {

  outfile << "CreateToolhelp32Snapshot调用失败!" << endl;
  return -1;
 }

 BOOL bMore = ::Process32First(hProcessSnap, &pe32);

 while (bMore)
 {
  outfile << "进程名称:           " << pe32.szExeFile << endl;
  outfile << "进程ID号:           " << pe32.th32ProcessID << endl;
  outfile << "进程引用数:         " << pe32.cntUsage << endl;
  outfile << "进程默认堆ID号:     " << pe32.th32DefaultHeapID << endl;
  outfile << "进程模块ID号:       " << pe32.th32ModuleID << endl;
  outfile << "进程的线程数:       " << pe32.cntThreads << endl;
  outfile << "进程的父进程ID:     " << pe32.th32ParentProcessID << endl;
  outfile << endl;
  bMore = ::Process32Next(hProcessSnap, &pe32);
 }

 ::CloseHandle(hProcessSnap);

 STARTUPINFO si = {sizeof(si)};
 PROCESS_INFORMATION pi;
 char * szCommandLine = "notepad ProcessList.txt";
 ::CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);

 ::CloseHandle(pi.hThread);
 ::CloseHandle(pi.hProcess);

 return 0;
}

抱歉!评论已关闭.