Private Const MAX_PATH = 260
Private Const TH32CS_SNAPPROCESS = 2&
Private Type PROCESSENTRY32
lSize As Long
lUsage As Long
lProcessId As Long
lDefaultHeapId As Long
lModuleId As Long
lThreads As Long
lParentProcessId As Long
lPriClassBase As Long
lFlags As Long
sExeFile 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 IsProcessActive(ByVal vnPID As Long) As Boolean
Dim hSnap As Long
Dim tProcess As PROCESSENTRY32
If vnPID Then
hSnap = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
If hSnap Then
tProcess.lSize = Len(tProcess)
If ProcessFirst(hSnap, tProcess) Then
Do
If tProcess.lProcessId = vnPID Then
IsProcessActive = True
Exit Do
End If
Loop While ProcessNext(hSnap, tProcess)
End If
CloseHandle hSnap
End If
End If
End Function