Search Amazon:

Enumerate all Currently Running Processes

On Windows 9x and 2000 machines it is a snap to enumerate all the processes running. Using the CreateToolHelpSnapshot API function you can create a snapshot of the processes running then loop through the snapshot with the Process32First and Process32Next functions. Listing all the modules associated with each process is similar using the Module32First and Module32Next functions. This is shown in both sample programs.

On Windows NT you must use the EnumProcesses and EnumProcessModules functions of PSAPI.dll to accomplish this. This is illustrated in the Process/Module list sample. PSAPI.dll typically is not included with Windows NT. You can find it on a C++ CD or from Microsofts Platform Development Kit on their site (click the MSDN link on my links page then search for it).

Enumerate the Processes Currently Running with CreateToolhelpSnapshot
Windows 9x and 2000 Version

Enumerate the Processes and Modules Currently Running on Win9X and WinNT
Windows NT Version

Download Source Code

Applies To

The CreateToolHelpSnapshot function is only available on Windows 95, 98 and Windows 2000. It will not work on NT4. On NT you must use PSAPI.dll. An copy is included but visit Microsoft's site for the latest.

Description of Windows 9x Version

To list all the process that are currently running, the CreateToolhelpSnapshot API is used. When called with the TH32CS_SNAPPROCESS flag CreateToolhelpSnapshot creates a snapshot of the processes. Once the snapshot is created we can enumerate through it using the Process32First and Process32Next functions. Both these functions take a PROCESSENTRY32 structure as a parameter. PROCESSENTRY32 is populated with the information shown in the above grid as well as other process related information. Enumerating modules is similar. For each process found, we use the Module32First and Module32Next APIs to enumerate the modules.

Instructions

Download the source code and press F5 to run the program.

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Comments: 1 Items to Show:     

     
Id:  1 Posted:  4/5/2007 3:35:02 PM By:  PanicMode
very nice example, just what i was looking for
 
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms