Attribute VB_Name = "modFindProcess" Option Explicit '====Example==== ' On Error Resume Next ' dim isProcRunning As Boolean ' isProcRunning = FindProcessFromEXE("MyApp.exe") Private Const TH32CS_SNAPPROCESS = &H2 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 Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As Any) As Long Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As Any) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long 'Public IsDebugMode As Boolean Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long 'tests if this application is running in the vb ide Public Function TestEnv() As Boolean Dim buffer As String Dim EnvFileName As String Dim Envs As Variant Dim nRet As Long Dim i As Long On Error Resume Next TestEnv = False Envs = Array("vb.exe", "vb32.exe", "vb5.exe", "vb6.exe") For i = LBound(Envs) To UBound(Envs) buffer = Envs(i) nRet = GetModuleHandle(buffer) If nRet <> 0 Then EnvFileName = buffer TestEnv = True Exit For End If Next End Function Public Function FindProcessFromEXE(ExeName As String) As Boolean Dim hSnapshot As Long Dim RetVal As Long Dim PE32 As PROCESSENTRY32 Dim strExeFile As String On Error Resume Next FindProcessFromEXE = False PE32.dwSize = Len(PE32) hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) If hSnapshot Then RetVal = Process32First(hSnapshot, PE32) Do While RetVal strExeFile = Left(PE32.szExeFile, InStr(PE32.szExeFile, Chr(0)) - 1) If UCase(ExeName) = UCase(strExeFile) Then FindProcessFromEXE = True Exit Do End If RetVal = Process32Next(hSnapshot, PE32) Loop RetVal = CloseHandle(hSnapshot) End If End Function