Rubrik: Windows/System | 28.07.01 |
Process32Next-Funktion Diese Funktion ermittelt den nächsten Prozess eines mit CreateToolhelp32Snapshot erstellten Snapshots. | ||
Betriebssystem: Win95, Win98, WinNT 4.0, Win2000, WinME | Views: 8.046 |
Deklaration:
Declare Function Process32Next Lib "kernel32.dll" ( _ ByVal hSnapshot As Long, _ lppe As PROCESSENTRY32) As Long
Beschreibung:
Diese Funktion ermittelt den nächsten Prozess eines mit CreateToolhelp32Snapshot erstellten Snapshots. Vor dem Ermitteln des nächsten Prozesses muss die Funktion Process32First aufgerufen werden.
Parameter:
hSnapshot | Erwartet einen Snapshot-Handle, welcher mit der CreateToolhelp32Snapshot-Funktion erstellt wurde. |
lppe | Erwartet eine PROCESSENTRY32-Struktur, deren Variable "dwSize" mit der Struktur Größe gesetzt ist. Wird mit den Daten des ersten Prozesses gefüllt. |
Rückgabewert:
Bei efolgreichem Funktionsaufruf ist der Rückgabewert ungleich 0, andernfalls wird zurückgegeben.
Beispiel:
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" ( _ ByVal dwFlags As Long, _ ByVal th32ProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32.dll" ( _ ByVal hSnapshot As Long, _ lppe As PROCESSENTRY32) As Long Private Declare Function Process32Next Lib "kernel32.dll" ( _ ByVal hSnapshot As Long, _ lppe As PROCESSENTRY32) As Long Private Declare Function CloseHandle Lib "kernel32.dll" ( _ ByVal hObject As Long) As Long Private Declare Function lstrlen Lib "kernel32" _ Alias "lstrlenA" ( _ ByVal lpString As String) As Long 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 Const TH32CS_INHERIT = &H80000000 Private Const TH32CS_SNAPALL = &HF Private Const TH32CS_SNAPHEAPLIST = &H1 Private Const TH32CS_SNAPPROCESS = &H2 Private Const TH32CS_SNAPTHREAD = &H4 Private Const TH32CS_SNAPMODULE = &H8
' alle laufenden Prozesse ermitteln Private Sub Command1_Click() Dim Retval As Long Dim hSnap As Long Dim PInfo As PROCESSENTRY32 ' Snapshot vom gesamten System erstellen hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&) If hSnap = -1 Then MsgBox "Der System-Snapshot konnte nicht erstellt werden.", _ vbInformation, "Fehler" Exit Sub End If PInfo.dwSize = Len(PInfo) Retval = Process32First(hSnap, PInfo) ' ersten Prozess ermitteln List1.Clear Do Until Retval = 0 With PInfo .szExeFile = Trim$(Left$(.szExeFile, lstrlen(.szExeFile))) _ ' VBNullChar abtrennen List1.AddItem "# " & Format$(Abs(.th32ProcessID), "00000000") & " - _ " & Mid$(.szExeFile, InStrRev(.szExeFile, "\") + 1) End With Retval = Process32Next(hSnap, PInfo) ' nächsten Prozess ermitteln DoEvents Loop CloseHandle hSnap ' Snapshot zerstören End Sub