Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is a task running?

Posted on 1998-11-17
2
Medium Priority
?
186 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 300 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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.
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

722 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