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.


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

About TheScarms
About TheScarms

Sample code
version info

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

Email this page

© Copyright 2024 TheScarms
Goto top of page