Is Process running? Prüfen, ob ein Prozess läuft.

Mit folgender Funktion lässt sich prüfen, ob ein Prozess läuft (Is Exe / Process running?), am besten in ein Modul kopieren:

Private Const TH32CS_SNAPPROCERSS = &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 PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long


Public Function IsExeRunning(ByVal ExeName As String) As Boolean
Dim hSnap As Long, pe As PROCESSENTRY32, ret As Long
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCERSS, 0)
If hSnap <> 0 Then
pe.dwSize = Len(pe)
ret = Process32First(hSnap, pe)
Do While ret <> 0
If Mid(pe.szexeFile, 1, InStr(1, pe.szexeFile, Chr(0)) - 1) = ExeName Then
IsExeRunning = True
Exit Do
End If
ret = Process32Next(hSnap, pe)
Loop
Else
IsExeRunning = False
End If
End Function