Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 14:46

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: processes list on Windows
PostPosted: 27 Aug 2007 21:09 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
The function for listing the modules on Windows is so short that I have pasted it directly in this message.
This function (derived by some code I found posted on extalia.com) can be useful to many people and as already said shows the modules.
Each process has its modules and the first module of a process is just the main executable while the others are (usually) the dll files called by it.
If you don't need all these informations you can directly remove the second STARTPROC so you will have only the process.
Watch the Win32 API guide for the info contained in PROCESSENTRY32 and MODULEENTRY32:

#include <windows.h>
#include <tlhelp32.h>

void process_list(void) {
PROCESSENTRY32 Process;
MODULEENTRY32 Module;
HANDLE snapProcess,
snapModule;
BOOL b;

#define STARTPROC(X,Y) \
snap##X = CreateToolhelp32Snapshot(Y, Process.th32ProcessID); \
X.dwSize = sizeof(X); \
for(b = X##32First(snap##X, &X); b; b = X##32Next(snap##X, &X)) { \
X.dwSize = sizeof(X);
#define ENDPROC(X) \
} \
CloseHandle(snap##X);

Process.th32ProcessID = 0;
STARTPROC(Process, TH32CS_SNAPPROCESS)
STARTPROC(Module, TH32CS_SNAPMODULE)

printf("%s\n", Module.szExePath);

ENDPROC(Module)
ENDPROC(Process)

#undef STARTPROC
#undef ENDPROC
}


Top
 Profile  
 
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: