I am trying to write a program, for practice, similar to the task manager, that lists running process, and their path if possible. I have spent hours all over Google and I can't find anything. Ideally, it would be nice to put the processes and their paths into an array, in this format:

list[0] = "C:\Game.exe";
list[1] = "C:\MusicPlayer.exe";
list[2] = "C:\Calculator.exe";

Any ideas?

8 Years
Discussion Span
Last Post by Duoas

Use CreateToolhelp32Snapshot() with the TH32CS_SNAPPROCESS flag and Process32First() and Process32Next() to get a list of processes on the system.

For each process, create another snapshot using the TH32CS_SNAPMODULE flag and the process ID. For each module ID use GetModuleFileName(), and look for the modules whose names end in ".exe".
The MSDN toolhelp documetation gives examples like how to traverese the module list.

Don't forget to use CloseHandle() on each snapshot when you are done with it.

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.