Solved

How to check if 2 or more applications are running?

Posted on 1998-09-04
3
125 Views
Last Modified: 2010-04-30
I need a source code that will check if the application that my program launched by SHELL command is still running.  My program is a scheduler, two applications can run at the same time and what I need is to check if both these applications are still running.  I tried a code which I got from a book that checks one application at a time, this does not suit my program because it inhibits the running of other scheduled applications.

Ex.  App1 - should run at 11:00AM
     App2 - should run at 11:01AM

Launch App1 at 11:00AM then a loop that will check if it still running.  App1 is still running at 11:01AM but my program sees that App2 should be run at 11:01AM thus it will run App2 at 11:01AM.  Then the program should check if these two applications are still running.

I hope someone can help me.
Thank you.
0
Comment
Question by:MokMok
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1433043
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFFFFFF
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

           
Dim pId As Long, pHnd As Long '

pId = Shell("Notepad", vbNormalFocus) '

pHnd = OpenProcess(SYNCHRONIZE, 0, pId) ' get Process Handle
If pHnd <> 0 Then
   Call WaitForSingleObject(pHnd, INFINITE) ' Wait until shelled
              prog ends
   Call CloseHandle(pHnd)
End If

0
 

Author Comment

by:MokMok
ID: 1433044
I have already tried this code.  The problem I get is that it waits for my first application to finish.  My first application has a long run time.  What I need is something that is flexible enough to run two application at the same time and performs a check if it is still running.
0
 
LVL 14

Expert Comment

by:waty
ID: 1433045
One solution, is storing the Pid returned by the shell and periodically use OpenProcess API to see if it is still in memory <>0.

That's all.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now