vb遍历所有系统进程???
答案:3 悬赏:0 手机版
解决时间 2021-07-28 09:50
- 提问者网友:谁的错
- 2021-07-28 06:02
请问用vb遍历系统进程所需要哪些API函数,请列举出来??
最佳答案
- 五星知识达人网友:鱼芗
- 2021-07-28 06:24
用到了ToolHelpAPI函数和结构,函数为:CreateToolhelp32Snapshot、Process32First、Process32Next和普通API CloseHandle。结构为:PROCESSENTRY32。 '进程结构定义 Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long'进程ID th32DefaultHeapID As Long'堆栈ID th32ModuleID As Long'模块ID cntThreads As Long th32ParentProcessID As Long'父进程ID pcPriClassBase As Long dwFlags As Long szExeFile As String * 260 End Type Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long '获取首个进程 Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long '获取下个进程 Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long '释放句柄 Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long) Private Const TH32CS_SNAPPROCESS = &H2& Private Sub EnumProcess() Dim SnapShot As Long Dim NextProcess As Long Dim PE As PROCESSENTRY32 '创建进程快照 SnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) '如果队列不为空则搜索 If SnapShot <> -1 Then '设置进程结构长度 PE.dwSize = Len(PE) '获取首个进程 NextProcess = Process32First(SnapShot, PE) Do While NextProcess ,可对进程序做相应处理 '获取下一个 NextProcess = Process32Next(SnapShot, PE) Loop '释放进程句柄 CloseHandle (SnapShot) End If End Sub
全部回答
- 1楼网友:千杯敬自由
- 2021-07-28 08:07
我这里有编好了的,你要是要我发给你
- 2楼网友:有你哪都是故乡
- 2021-07-28 06:57
'模块
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'该函数是EnumWindows的回调函数,EnumWindows函数将遍历的窗口句柄传递到hwnd参数中
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim astr As String * 256
Dim l As Long
l = GetWindowText(hwnd, astr, Len(astr))
If InStr(astr, " ") > 1 Then
Form1.List1.AddItem astr
End If
EnumWindowsProc = True
End Function
'窗体
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Sub Command1_Click()
Dim l As Long
List1.Clear
'遍历所有的窗口
l = EnumWindows(AddressOf EnumWindowsProc, 0)
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯