D
doug
Can someone point me to the error of my ways here? I get a
'System.NotSupportedException' on the Process32Next call.
Imports System.Runtime.InteropServices
Private Const TH32CS_SNAPPROCESS As Integer = 2&
Private Const MAX_PATH As Integer = 260
Private Structure PROCESSENTRY32
Dim dwSize As Integer
Dim cntUsage As Integer
Dim th32ProcessID As Integer
Dim th32DefaultHeapID As Integer
Dim th32ModuleID As Integer
Dim cntThreads As Integer
Dim th32ParentProcessID As Integer
Dim pcPriClassBase As Integer
Dim dwFlags As Integer
Dim szExeFile() As Byte
Dim th32MemoryBase As Integer
Dim th32AccessKey As Integer
End Structure
Private Declare Function CreateToolhelp32Snapshot Lib "toolhelp.dll"
(ByVal lFlags As Integer, ByVal lProcessID As Integer) As Integer
Private Declare Function Process32First Lib "toolhelp.dll" (ByVal
hSnapShot As Integer, ByRef uProcess As PROCESSENTRY32) As Boolean
Private Declare Function Process32Next Lib "toolhelp.dll" (ByVal
hSnapShot As Integer, ByRef uProcess As PROCESSENTRY32) As Boolean
Private Declare Function CloseToolhelp32Snapshot Lib "toolhelp.dll"
(ByVal hPass As Integer) As Integer
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hSnapShot As Integer
Dim uProcess As PROCESSENTRY32
Dim success As Boolean
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = -1 Then Exit Sub
ReDim Preserve uProcess.szExeFile(MAX_PATH - 1)
uProcess.dwSize = 304 'marshal.sizeof(uProcess)
success = Process32First(hSnapShot, uProcess)
If success Then
Do
List1.Items.Add(uProcess.szExeFile)
Loop While Process32Next(hSnapShot, uProcess)
End If
Call CloseToolhelp32Snapshot(hSnapShot)
End Sub
'System.NotSupportedException' on the Process32Next call.
Imports System.Runtime.InteropServices
Private Const TH32CS_SNAPPROCESS As Integer = 2&
Private Const MAX_PATH As Integer = 260
Private Structure PROCESSENTRY32
Dim dwSize As Integer
Dim cntUsage As Integer
Dim th32ProcessID As Integer
Dim th32DefaultHeapID As Integer
Dim th32ModuleID As Integer
Dim cntThreads As Integer
Dim th32ParentProcessID As Integer
Dim pcPriClassBase As Integer
Dim dwFlags As Integer
Dim szExeFile() As Byte
Dim th32MemoryBase As Integer
Dim th32AccessKey As Integer
End Structure
Private Declare Function CreateToolhelp32Snapshot Lib "toolhelp.dll"
(ByVal lFlags As Integer, ByVal lProcessID As Integer) As Integer
Private Declare Function Process32First Lib "toolhelp.dll" (ByVal
hSnapShot As Integer, ByRef uProcess As PROCESSENTRY32) As Boolean
Private Declare Function Process32Next Lib "toolhelp.dll" (ByVal
hSnapShot As Integer, ByRef uProcess As PROCESSENTRY32) As Boolean
Private Declare Function CloseToolhelp32Snapshot Lib "toolhelp.dll"
(ByVal hPass As Integer) As Integer
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hSnapShot As Integer
Dim uProcess As PROCESSENTRY32
Dim success As Boolean
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = -1 Then Exit Sub
ReDim Preserve uProcess.szExeFile(MAX_PATH - 1)
uProcess.dwSize = 304 'marshal.sizeof(uProcess)
success = Process32First(hSnapShot, uProcess)
If success Then
Do
List1.Items.Add(uProcess.szExeFile)
Loop While Process32Next(hSnapShot, uProcess)
End If
Call CloseToolhelp32Snapshot(hSnapShot)
End Sub