标题:VB Process32First总是返回0
只看楼主
时光流逝
Rank: 4
来 自:北京
等 级:业余侠客
威 望:8
帖 子:92
专家分:297
注 册:2019-11-16
结帖率:100%
 问题点数:0 回复次数:0 
VB Process32First总是返回0
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (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

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
搜索更多相关主题的帖子: ByVal 获取 ListView Long 进程 
2020-12-16 22:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-504286-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.207885 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved