Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out if a .exe is running in c++?

How can you find out if an executable is running on Windows given the process name, e.g. program.exe?

like image 437
blood Avatar asked Jan 21 '23 16:01

blood


1 Answers

The C++ standard library has no such support. You need an operating system API to do this. If this is Windows then you'd use CreateToolhelp32Snapshot(), followed by Process32First and Process32Next to iterate the running processes. Beware of the inevitable race condition, the process could have exited by the time you found it.

like image 93
Hans Passant Avatar answered Jan 29 '23 09:01

Hans Passant