Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if a process is running

Status
Not open for further replies.

BlackTL

Technical User
Aug 11, 2003
29
US
Hi All,

I need to check if a particular process is running from within my code. Basically, the application gets it's data from another application and if that application is not running, the code should start that application as well. Has anoone done this before in Visual C++?

Thank you.
 
The best way I think would be if the application you want to get data from is COM-based. Then by using CoCreateInstance from the application that needs the data, COM would connect to the other application if it is already running, or start it up if it was not. Then the interface you get back from the function call would allow the two applications to communicate with each other.

Another way you could do this is by having the application you want to get data from create a named pipe or event. Then the other application can attempt to open the pipe or event. If it opens, the other application is running, and if you use a pipe you could even use it to pass data between the two applications. If the pipe/event doesn't open, you know the other application is not running, and you can then start it from there. This is because named pipes/events are automatically deleted once there are no more applications running that have handles open to them.

Another thing to try, if the applications create top level windows, is to have the application needing data enumerate all the top level windows, using the EnumWindows function. If you find a window with a title or class information that matches the other application, you know that application is already running, and could even use its window handle to post messages to it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top