// 01ProcessList.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<windows.h>
#include<tlhelp32.h>
#include<stdio.h>
int main(int argc, char* argv[])
{
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hProcessSnap == INVALID_HANDLE_VALUE)
{
return -1;
}
BOOL bmore = ::Process32First(hProcessSnap,&pe32);
while(bmore)
{
printf("进程名称 %s/n",pe32.szExeFile);
printf("进程字节大小 %2d/n",pe32.dwSize);
printf("进程默认堆ID %2d/n",pe32.th32DefaultHeapID);
printf("进程父进程ID %2d/n", pe32.th32ParentProcessID);
printf("进程ID %2d/n",pe32.th32ProcessID);
printf("/n");
bmore = ::Process32Next(hProcessSnap,&pe32);
}
DWORD dw = ::GetCurrentProcessId();
printf("此进程ID %d/n",dw);
return 0;
}