VB中怎么查看任务管理器中的进程列表
VB中如何查看任务管理器中的进程列表?
问题1:VB中如何查看任务管理器中的进程列表?
问题2:如果通过调用windows的Tasklist命令行,则VB 获取查询后的报文?
------解决方案--------------------
Option Explicit
'////////////////////////////////////////////////////////////////////////
'查看进程所有的API和声明
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Const MAX_PATH As Integer = 260
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 * MAX_PATH
End Type
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const TH32CS_SNAPPROCESS = &H2
Private Const TH32CS_SNAPheaplist = &H1
Private Const TH32CS_SNAPthread = &H4
Private Const TH32CS_SNAPmodule = &H8
Private Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
Private CjId() As Long '进程ID
Private Function GetJingCheng() As String ' 取得进程
GetJingCheng = ""
Dim i As Long
Dim theloop As Long
Dim proc As PROCESSENTRY32
Dim snap As Long
Dim Exename As String
GetJingCheng = "" '清空所有内容
snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '获得进程“快照”的句柄
proc.dwSize = Len(proc)
theloop = ProcessFirst(snap, proc) '获取第一个进程,并得到其返回值
i = 0
While theloop <> 0 '当返回值非零时继续获取下一个进程
'GetJingCheng = GetJingCheng & proc.szExeFile & Chr(2) & proc.th32ProcessID & Chr(2)
List1.AddItem proc.szExeFile
ReDim Preserve CjId(i)
CjId(i) = proc.th32ProcessID
i = i + 1
theloop = ProcessNext(snap, proc)
Wend
CloseHandle snap '关闭进程“快照”句柄
End Function
Private Function EndJingCheng(MyId As Long) As Long ' 结束进程
Dim i As Long
Dim Mystr As String
Dim hand As Long
hand = OpenProcess(1, True, MyId) '获取进程句柄
EndJingCheng = TerminateProcess(hand, 1) '关闭进程
'刷新管理端的进程列表
Mystr = GetJingCheng()
End Function
Private Sub Command1_Click()
GetJingCheng
End Sub
Private Sub Command2_Click()
Dim l As Long
If List1.ListIndex > 0 Then
l = CjId(List1.ListIndex)
EndJingCheng l
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "列出进程"
Command2.Caption = "结束进程"
End Sub
------解决方案--------------------
http://topic.****.net/t/20020731/16/913990.html
问题1:VB中如何查看任务管理器中的进程列表?
问题2:如果通过调用windows的Tasklist命令行,则VB 获取查询后的报文?
------解决方案--------------------
Option Explicit
'////////////////////////////////////////////////////////////////////////
'查看进程所有的API和声明
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Const MAX_PATH As Integer = 260
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 * MAX_PATH
End Type
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const TH32CS_SNAPPROCESS = &H2
Private Const TH32CS_SNAPheaplist = &H1
Private Const TH32CS_SNAPthread = &H4
Private Const TH32CS_SNAPmodule = &H8
Private Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
Private CjId() As Long '进程ID
Private Function GetJingCheng() As String ' 取得进程
GetJingCheng = ""
Dim i As Long
Dim theloop As Long
Dim proc As PROCESSENTRY32
Dim snap As Long
Dim Exename As String
GetJingCheng = "" '清空所有内容
snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '获得进程“快照”的句柄
proc.dwSize = Len(proc)
theloop = ProcessFirst(snap, proc) '获取第一个进程,并得到其返回值
i = 0
While theloop <> 0 '当返回值非零时继续获取下一个进程
'GetJingCheng = GetJingCheng & proc.szExeFile & Chr(2) & proc.th32ProcessID & Chr(2)
List1.AddItem proc.szExeFile
ReDim Preserve CjId(i)
CjId(i) = proc.th32ProcessID
i = i + 1
theloop = ProcessNext(snap, proc)
Wend
CloseHandle snap '关闭进程“快照”句柄
End Function
Private Function EndJingCheng(MyId As Long) As Long ' 结束进程
Dim i As Long
Dim Mystr As String
Dim hand As Long
hand = OpenProcess(1, True, MyId) '获取进程句柄
EndJingCheng = TerminateProcess(hand, 1) '关闭进程
'刷新管理端的进程列表
Mystr = GetJingCheng()
End Function
Private Sub Command1_Click()
GetJingCheng
End Sub
Private Sub Command2_Click()
Dim l As Long
If List1.ListIndex > 0 Then
l = CjId(List1.ListIndex)
EndJingCheng l
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "列出进程"
Command2.Caption = "结束进程"
End Sub
------解决方案--------------------
http://topic.****.net/t/20020731/16/913990.html