#include #include #include /* tool help library */ /* Something like the Unix ps command - lists all processes in the system. For each process shows the pid and the filename This program uses the tool help library. There is a more complete example available at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/taking_a_snapshot_and_viewing_processes.asp */ int main(int argc, char **argv) { HANDLE snapshot; /* used to hold a snapshot of all running processes */ PROCESSENTRY32 lppe; /* holds info on one process */ BOOL notdone; /* just a boolean flag */ /* Grab a snapshot of all running processes */ snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,0); if (snapshot==INVALID_HANDLE_VALUE) { printf("Error calling CreateToolhelp32Snapshot" ); exit(1); } /* Initialize the PROCESSENTRY structure to hold it's own size */ lppe.dwSize = sizeof(PROCESSENTRY32); /* grab info about the first process in the list */ notdone = Process32First(snapshot,&lppe); while ( notdone) { /* print the pid and file */ printf("%d\t%s\n",lppe.th32ProcessID,lppe.szExeFile); /* grab info about the next process in the list */ notdone = Process32Next(snapshot,&lppe); } return(0); }