Dichiarare:
Option Explicit
Private Const TH32CS_SNAPPROCESS = &H2
Private Const MAX_PATH As Integer = 260
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 * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hObject As Long)
Poi inserire:
Private Sub Command1_Click()
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim lngRet As Long
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
uProcess.dwSize = Len(uProcess)
lngRet = Process32First(hSnapShot, uProcess)
lbprocessi.Clear
Do While lngRet
lbprocessi.AddItem Left$(uProcess.szExeFile, InStr(1, uProcess.szExeFile, vbNullChar) - 1)
lngRet = Process32Next(hSnapShot, uProcess)
Loop
CloseHandle hSnapShot
Dim x As Integer
Dim a As Double
Dim proc As Boolean
x = -1
For a = 1 To lbprocessi.ListCount
x = x + 1
Next
end sub