- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0 |
今天给出一个进程管理器的VB代码,可以获得系统中的所有进程,并可以结束选定的进程,不过如果是系统用进程则不能结束。制作:在FORM中添加1个ListView和2个Command控件,然后添加如下代码:
Option Explicit
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 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
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
Const TH32CS_SNAPheaplist = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPthread = &H4
Const TH32CS_SNAPmodule = &H8
Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
Private Sub Command1_Click()
Dim i As Long, lPid As Long
Dim Proc As PROCESSENTRY32
Dim hSnapShot As Long
ListView1.ListItems.Clear '清空ListView
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '获得进程“快照”的句柄
Proc.dwSize = Len(Proc)
lPid = ProcessFirst(hSnapShot, Proc) '获取第一个进程的PROCESSENTRY32结构信息数据
i = 0
Do While lPid <> 0 '当返回值非零时继续获取下一个进程
ListView1.ListItems.Add , "a" & i, Hex(Proc.th32ProcessID) '将进程ID添加到ListView1第一列
ListView1.ListItems("a" & i).SubItems(1) = Proc.szExeFile '将进程名添加到ListView1第二列
i = i + 1
lPid = ProcessNext(hSnapShot, Proc) '循环获取下一个进程的PROCESSENTRY32结构信息数据
Loop
CloseHandle hSnapShot '关闭进程“快照”句柄
End Sub
Private Sub Command2_Click()
Dim lPHand As Long, TMBack As Long
If ListView1.SelectedItem.Text <> "" Then
If MsgBox("确实要结束进程[" & ListView1.SelectedItem.SubItems(1) & "]吗?", vbYesNo) = vbYes Then
lPHand = Val("&H" & ListView1.SelectedItem.Text)
lPHand = OpenProcess(1&, True, lPHand) '获取进程句柄
TMBack = TerminateProcess(lPHand, 0&) '关闭进程
If TMBack <> 0 Then
MsgBox ListView1.SelectedItem.SubItems(1) & "已经被终止!"
Else
MsgBox ListView1.SelectedItem.SubItems(1) & "不能被终止!"
End If
CloseHandle lPHand
Command1_Click '刷新进程列表
End If
End If
End Sub
Private Sub Form_Load()
Me.Caption = "进程管理器"
Command1.Caption = "刷新"
Command2.Caption = "结束进程"
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , "a", "进程ID", 600
ListView1.ColumnHeaders.Add , "b", "进程名", 4000
ListView1.View = lvwReport
Command1_Click '刷新进程列表
End Sub
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |