Checking if an exe file is running with c++

Started by
4 comments, last by antareus 19 years, 4 months ago
Hi I have two seperate exe files and I am looking for some ideas as to how I can deterimine if the other one is running so I can set the other one to sleep. Any help would be most appreciated :) [Edited by - Z4Gamer on December 15, 2004 7:23:13 AM]
Advertisement
You can use CreateMutex() to create a named mutex in one application, and then try to create a mutex with the same name in the other one. If the other application is running, GetLastError() will return ERROR_ALREADY_EXISTS.
~neoztar "Any lock can be picked with a big enough hammer"my website | opengl extensions | try here firstguru of the week | msdn library | c++ faq lite
I am current executing the second file using this

WinExec("Application.exe",SW_SHOWMAXIMIZED);

Is there any other way I can check to see if its running without using Mutex as I have had lots of problems with them in the past :eek:
You could try to create a hidden window and see if you can find it with FindWindow().
~neoztar "Any lock can be picked with a big enough hammer"my website | opengl extensions | try here firstguru of the week | msdn library | c++ faq lite
Just thought of something: Use CreateProcess() to start the application, and save the process id, which you can then use with OpenProcess() to see if it's still running. Check MSDN for details.
~neoztar "Any lock can be picked with a big enough hammer"my website | opengl extensions | try here firstguru of the week | msdn library | c++ faq lite
Don't futz around with hidden windows and the like, especially when running a console app. Using a mutex is the way to go.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis

This topic is closed to new replies.

Advertisement