Solved

How to check if 2 or more applications are running?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Computer crashes, following error message in event manager 5 238
How to debug this code 7 64
Protecting vb6 & .Net code Obfuscation 18 152
Recommendation vb6 to vb.net or others 14 176
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

860 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