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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Processes State

Status
Not open for further replies.

ibel

Programmer
Feb 12, 2002
4
ES
Hi all!

I am developing a windows service that check for the state of some application running to manage them. I would like to know how I can know if the application is running or not, the same thing Windows task manager does. Other way is to access in some way to the process state, but I don't know how to do it.

Some ideas about that?

Thanks to all in advance. :-D

 
Assuming all the applications you are talking about run on the same workstation (otherwise you need networking):

You can use named mutexes to get information if processes are running or not. If every application creates a mutex with a name unique to that application, it is possible to find out if the application is running or not. But, this does not tell you how many of those processes are running. A named semaphore with an initial count high enough to support as many of them as you want lets you also figure out how many of them are running.

To get further information, you need to have a process handle of the processes. There are some ways to do that:
1. If one program starts all the others, this program has all the process handles returned from CreateProcess or ShellExecute.
2. You can use FindWindow, followed by GetWindowThreadProcessId, followed by OpenProcess to get a process handle

Once you have the processhandles, call GetExitCodeProcess to find out if it is still running or not.

Communicate between processes can be done by filemapping.

This is only a subset of possibilities, there are many other API's available. If you tell exactly what you want, perhaps I can give more specific information.

Marcel
 
Thanks MKuiper!

I know if an application is running or not, but what I want to know is the state. What I mean is if it is running, is blocked... The state that Windows Task Manager, when shows the applications and the state of them, I don't know if you understand me.

Thanks again
 
If you have access to the Platform SDK documentation, search for CreateToolhelp32Snapshot. The entire chapter which has this function in it, contains the information which, I guess, you need.

Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top