Page 1 of 1
[C++] Find out if a program is running?
Posted: Fri Jul 06, 2007 12:55 am
by toasty2
How can I check if a program is running (on Windows) with C++? Some places suggest FindWindow or something like that, but all those suggestions are on newsgroups back in 1999 and 2000. I am using Dev-C++ (seems to support a most of VC++'s libraries). What method can I use to tell if a certain program is running? I am writing a monitoring app.
Posted: Fri Jul 06, 2007 1:24 am
by feyd
Use mutexes.
Posted: Fri Jul 06, 2007 4:07 am
by Gente
Posted: Fri Jul 06, 2007 4:48 am
by volka
toasty2 wrote:What method can I use to tell if a certain program is running?
Do you want to monitor yopur own program (that you can modify) or do you want to monitor arbitrary programs?
toasty2 wrote:Some places suggest FindWindow or something like that, but all those suggestions are on newsgroups back in 1999 and 2000
FindWindow is still a valid function.
You might also be interested in EnumProcesses.
see also:
http://msdn2.microsoft.com/en-us/library/ms633499.aspx
http://msdn2.microsoft.com/en-us/library/ms682629.aspx
Posted: Fri Jul 06, 2007 7:15 am
by alex.barylski
Alternatively you can look into: Process32First() and related functions...
This is perhaps of interest as well:
http://www.alexfedotov.com/articles/enumproc.asp
Cheers

Posted: Fri Jul 06, 2007 11:29 am
by toasty2
volka wrote:Do you want to monitor yopur own program (that you can modify) or do you want to monitor arbitrary programs?
No, I will be monitoring other programs (a few server apps). I plan on running a loop that every 30 seconds does whichever method I decide to use to check if the programs are running. Thanks everyone, I'll try using a few of these methods.
Edit: What library is FindWindow in?
feyd, I'm confused by CreateMutex, what is it exactly?
Posted: Fri Jul 06, 2007 11:46 am
by feyd
Hang on, you're checking programs you don't control? Enumerate the processes then.
Posted: Fri Jul 06, 2007 11:50 am
by volka
toasty2 wrote:Edit: What library is FindWindow in?
But win32 services usually do not have windows. In fact you need to specifically allow services to interact with the desktop.
Posted: Fri Jul 06, 2007 11:59 am
by toasty2
How do I do that?
Posted: Fri Jul 06, 2007 12:17 pm
by volka
e.g in the service control panel. But that only allows a service to interact with the desktop. It does not force a service app to create a window. Services usually do not have windows.
Posted: Fri Jul 06, 2007 3:27 pm
by toasty2
With the first method at
http://www.alexfedotov.com/articles/enumproc.asp,
how do I check for a particular exe? How do I utilize the code?
Posted: Fri Jul 06, 2007 3:50 pm
by stereofrog
Posted: Sun Jul 08, 2007 12:47 pm
by alex.barylski
My best advice to you, would be to ask this question over at the codeproject.com a community of dedicated Windows developers. There is likely an article floating around somewhere.
p.s-Why are you using Dev-C++
There is a free version of Visual C++ called Express. Far better for working on Windows apps than BloodShed. Unless you have plans on porting to Linux, in which case use the wxWidgets library and BloodShed.
http://msdn.microsoft.com/vstudio/express/visualc/
Cheers
