Solved

Is a task running?

Posted on 1998-11-17
2
173 Views
Last Modified: 2010-05-03
From Program A, what is the best way to determine if Executable B is running prior to shelling B out.  The class and caption of Executable B are unknown.  All that is known about B is it's path and executable name.      
0
Comment
Question by:jphalen
[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 Comments
 

Accepted Solution

by:
TAD062998 earned 100 total points
ID: 1445309
This is the version for 95 ( not tested on 98 yet but it should work)
The version for NT requires an additional 'free' .dll (Psapi.dll)
If you need that code let me know.

Add the following to a .bas module :

Private Const TH32CS_SNAPPROCESS As Long = 2&
Private Const MAX_PATH           As Integer = 260

Private Type PROCESSENTRY32
    dwSize              As Long
    cntUsage            As Long
    th32ProcessID       As Long
    th32DefaultHeapID   As Long
    th32ModuleID        As Long
    cntThreads          As Long
    th32ParentProcessID As Long
    pcPriClassBase      As Long
    dwFlags             As Long
    szExeFile           As String * MAX_PATH
End Type

Private Declare Function CreateToolhelpSnapshot Lib "Kernel32" _
                Alias "CreateToolhelp32Snapshot" _
                (ByVal lFlags As Long, ByVal lProcessID As Long) As Long

Private Declare Function ProcessFirst Lib "Kernel32" _
                Alias "Process32First" _
                (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long

Private Declare Function ProcessNext Lib "Kernel32" _
                Alias "Process32Next" _
                (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long

Private Declare Sub CloseHandle Lib "Kernel32" _
                (ByVal hPass As Long)

Public Function IsAppRunning95(ByVal sApp As String) As Boolean

    Dim hSnapshot   As Long
    Dim lContinue   As Long
    Dim bFound      As Boolean
    Dim pe32        As PROCESSENTRY32
     
    hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0)
     
    pe32.dwSize = LenB(pe32)
     
    lContinue = ProcessFirst(hSnapshot, pe32)
    bFound = False
    Do
        If UCase(sApp) = UCase(Left(pe32.szExeFile, InStr(1, pe32.szExeFile, Chr$(0)) - 1)) Then
           bFound = True
           Exit Do
        End If

        lContinue = ProcessNext(hSnapshot, pe32)
    Loop While lContinue   ' If True, return 1
     
    If bFound = True Then
        IsAppRunning95 = True
    Else
        IsAppRunning95 = False
    End If
   
    Call CloseHandle(hSnapshot)

End Function

Then, in your application use :

    If IsAppRunning95("C:\Windows\MyApplication.exe") Then
        MsgBox "Yes"
    Else
        MsgBox "No"
    End If

0
 

Author Comment

by:jphalen
ID: 1445310
If it is running, how would I get the handle so ShowWindow can be called?
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

740 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