//#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>
int main(int argc, char* argv[])
{
printf("进程ID\t\t进程名\n");
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof (pe32);
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(INVALID_HANDLE_VALUE == hProcessSnap)
{
printf("CreateToolhelp32Snapshot 调用失败\n");
return -1;
}
BOOL bMore = ::Process32First(hProcessSnap,&pe32);
while(bMore)
{
printf("%5u\t%s\n",pe32.th32ProcessID,pe32.szExeFile);
bMore = ::Process32Next(hProcessSnap,&pe32);
}
CloseHandle(hProcessSnap);
return 0;
}