Solved

How to check if 2 or more applications are running?

Posted on 1998-09-04
3
128 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

929 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

14 Experts available now in Live!

Get 1:1 Help Now