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 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 Sub GetProcesos(Procesos() As Variant)
Dim lngSnapShot As Long
lngSnapShot = CreateToolhelpSnapshot(2&, 0&)
If lngSnapShot <> 0 Then
Dim Proceso As PROCESSENTRY32
Proceso.dwSize = Len(Proceso)
Dim lngRc As Long, lngCta As Long
lngRc = ProcessFirst(lngSnapShot, Proceso)
Do While lngRc
lngCta = lngCta + 1
ReDim Preserve Procesos(2, lngCta)
Procesos(0, lngCta - 1) = Proceso.th32ProcessID
Procesos(1, lngCta - 1) = Left(Proceso.szExeFile, InStr(Proceso.szExeFile, Chr(0)) - 1)
lngRc = ProcessNext(lngSnapShot, Proceso)
Loop
CloseHandle lngSnapShot
End If
End Sub