VB Process32First总是返回0
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As LongPrivate 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
Public Sub GetProcessList(ListView As ListView)
Dim hSnapShot As Long, Proc As PROCESSENTRY32, theloop As Long
ListView.ListItems.Clear '清空ListView
'Proc.dwSize = Len(Proc)
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '获得进程“快照”的句柄
theloop = Process32First(hSnapShot, Proc) '获取第一个进程的PROCESSENTRY32结构信息数据------------------------------------------------------就是这里
MsgBox GetLastError
Do While theloop <> 0 '当返回值非零时继续获取下一个进程
ListView.ListItems.Add , , Proc.th32ProcessID '将进程ID添加到ListView1第一列
ListView.ListItems(ListView.ListItems.Count).SubItems(1) = Proc.szExeFile
ProcessCount = ProcessCount + 1
If Not Assert(OpenProcess(PROCESS_ALL_ACCESS, False, Proc.th32ProcessID)) Then NotAccessCount = NotAccessCount + 1
theloop = Process32Next(hSnapShot, Proc) '循环获取下一个进程的PROCESSENTRY32结构信息数据
Loop
CloseProcess hSnapShot
End Sub