Solved

How to check if 2 or more applications are running?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 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