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


Is a programm running?

Posted on 1999-07-21
Medium Priority
Last Modified: 2012-05-04
Does anyone can tell me if there is an API function that allows me to know if a program is currently running. The only data i will pass to the function is the application name (program name); I don't want to use the FindWindow API function cause it doesn't work as I expect?
If you have the answer please E-mail me at
Question by:hasselt
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
LVL 18

Accepted Solution

deighton earned 600 total points
ID: 1526433
call this with the full program name e.g. notepad.exe to return true (running) or false(not)

      Option Explicit

      Private Declare Function Process32First Lib "kernel32" _
      (ByVal hSnapshot As Long, lppe As _
      PROCESSENTRY32) As Long

      Private Declare Function Process32Next Lib "kernel32" _
      (ByVal hSnapshot As Long, lppe As _
      PROCESSENTRY32) As Long

      Private Declare Function CreateToolhelp32Snapshot Lib _
      "kernel32" (ByVal dwFlags As Long, _
      ByVal th32ProcessID As Long) As Long

      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 * 260
      End Type

      Private Const TH32CS_SNAPPROCESS = &H2&
      Private Const hNull = 0

      Public Function ExeRunning(ByVal ExeFind As String) As Boolean

          Dim hProc As Long, ExeName As String
          Dim lRet As Long, Proc As PROCESSENTRY32
          Dim g As Long, sDeighton As String
          Dim sClean As String
          Dim sAtom As String
          hProc = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
          ExeRunning = False
          If hProc = 0 Then
              Exit Function
          End If
          Proc.dwSize = Len(Proc)
          lRet = Process32First(hProc, Proc)
          Do While lRet
              ExeName = Left(Proc.szExeFile, Len(Proc.szExeFile) - 1)
              sClean = ""
              For g = 1 To Len(ExeName)
                sAtom = Mid(ExeName, g, 1)
                If sAtom = Chr(0) Then
                     Exit For
                    sClean = sClean & sAtom
                End If
              sDeighton = ""
              For g = Len(sClean) To 1 Step -1
                If Mid(sClean, g, 1) = "\" Then Exit For
                sDeighton = Mid(sClean, g, 1) & sDeighton
              If UCase(sDeighton) = UCase(ExeFind) Then
                  ExeRunning = True
                  Exit Function
              End If
              lRet = Process32Next(hProc, Proc)

      End Function


Author Comment

ID: 1526434
I have problems with the API functions: The problem is that the program doesn’t recognize them so the system sends the following error:
“ Run time error 453 Can’t find DLL entry point CreateToolHelp32Snapshot in Kernel32. “
Can you please help me to solve it?

LVL 18

Expert Comment

ID: 1526435
What Windows version do you use?  I run Windows 95.

Expert Comment

ID: 5119580
Use App Object and PrevInstance

Sub form_load()
    Dim SaveTitle As String
    On Error Resume Next
    If App.PrevInstance Then
      SaveTitle = App.Title
      App.Title = "... duplicate instance."
      Form1.Caption = "... duplicate instance."
      AppActivate SaveTitle
    End If
End sub

This will not allow another instance to start - if one is running

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Suggested Courses

704 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