Solved

How to check if 2 or more applications are running?

Posted on 1998-09-04
3
136 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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 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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Suggested Courses
Course of the Month4 days, 8 hours left to enroll

635 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