Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC Process
Hello,
 
I write a code and using MFC.
I want to check if process exists or not.
 
for example:
if (myProcess.exe exists)
  do something
else
  do something else
 
How can I do it?
 
Thanks
Posted 9-Jun-12 22:08pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If the process you're looking for has a GUI then you can use FindWindow to see if the window exists. If it does, the process is running. If not it doesn't necessarily mean it's not - it could be running in a different window station.
 
If you can modify the source code for the process you want to detect you could create a named semaphore and raise it everytime the process is launched. Then the detecting process can look for the semaphore by name.
 
If you don't have control over the source code you can use the toolhelp API to dredge through all the processes running using CreateToolHelp32Snapshot, Process32First and Process32First. This[^] article has a code example, bit crap but still usable.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I did process enumeration and searching for a process in my article here:
 
Professional System Library: Introduction[^]
 
You will see that the demo itself lists processes, and allows you to kill one.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
erez_l at 10-Jun-12 4:28am
   
Hi, Thanks for your answer.
I did it but got an error: "the procedure entry point k32 enumprocesses could not be located in the dynamic link library KERNEL32.dll". How Can I solve it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 10 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100