Public Class Form1 Inherits System.Windows.Forms.Form Public zj Public myProcesses() As Process Public myProcess As Process Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() myProcesses = Process.GetProcesses() For Each myProcess In myProcesses ListBox1.Items.Add(myProcess.ProcessName) Next Label1.Text = "" Label1.Text = "本机共有" & ListBox1.Items.Count & "个进程在运行" End Sub Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick Dim i : Dim f As Integer : Dim h As Integer ListBox2.Items.Clear() zj = ListBox1.SelectedIndex Label2.Text = "进程" & ListBox1.Items.Item(zj) & "的相关信息" With ListBox2.Items If myProcesses(zj).MainWindowTitle = "" Then .Add("无相关主窗口") Else .Add(myProcesses(zj).MainWindowTitle) End If .Add(myProcesses(zj).BasePriority & "进程的基本优先级") .Add(myProcesses(zj).Handle.ToString & "进程的本机句柄") .Add(myProcesses(zj).HandleCount & "进程打开的句柄数") .Add(myProcesses(zj).Id & "进程的唯一标识符") .Add(myProcesses(zj).MachineName & "进程正在其上运行的计算机的名称") .Add(myProcesses(zj).MainModule.ToString & "进程的主模块") .Add(myProcesses(zj).MainWindowHandle.ToString & "进程主窗口的句柄") '.Add(myProcesses(zj).Modules & "") .Add(myProcesses(zj).NonpagedSystemMemorySize & "分配给此进程的未分页的系统内存大小") .Add(myProcesses(zj).PagedMemorySize & "分页的内存大小") .Add(myProcesses(zj).PagedSystemMemorySize & "分页的系统内存大小") .Add(myProcesses(zj).PeakPagedMemorySize & "峰值分页内存大小") .Add(myProcesses(zj).PeakVirtualMemorySize & "峰值虚拟内存大小") .Add(myProcesses(zj).PrivateMemorySize & "专用内存大小") .Add(myProcesses(zj).StartTime & "进程启动的时间") .Add(myProcesses(zj).TotalProcessorTime.Seconds & "进程的总的处理器时间") .Add(myProcesses(zj).UsERProcessorTime.Seconds & "进程的用户处理器时间") .Add(myProcesses(zj).VirtualMemorySize & "进程的虚拟内存大小") End With ListBox3.Items.Clear() TabPage1.Text = "进程" & ListBox1.Items.Item(zj) & "的基本信息" TabPage2.Text = "进程" & ListBox1.Items.Item(zj) & "相关的线程信息" TabPage3.Text = "进程" & ListBox1.Items.Item(zj) & "相关的模块信息" '///////////////////////////////////////////// f = myProcesses(zj).Threads.Count Label4.Text = "进程" & ListBox1.Items.Item(zj) & "共有" & f & "个相关的线程,线程ID信息如下:" Dim int, pk, m, n For n = 0 To f - 1 ListBox3.Items.Add(myProcesses(zj).Threads(n).Id) Next '/////////////////////////////////////// ListBox5.Items.Clear() Dim zha, kl zha = myProcesses(zj).Modules.Count Label5.Text = "与进程" & ListBox1.Items.Item(zj) & "共有" & zha & "个相关的模块,模块位置信息如下:" For kl = 0 To zha - 1 ListBox5.Items.Add(myProcesses(zj).Modules(kl).FileName) Next End Sub Private Sub ListBox3_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox3.DoubleClick ListBox4.Items.Clear() Dim f, n f = myProcesses(zj).Threads.Count n = ListBox3.SelectedIndex Label6.Text = "线程" & ListBox3.Items.Item(n) & "相关信息" With ListBox4.Items‘与进程相关的线程信息见System.Diagnostics.processThread类。因为Processes.threads属性是返回thread对象数组而thread对象数组的实例是由ProcessThread类来创建,thread对象数组的信息是包含在System.Diagnostics. ProcessThread类中。 .Add(myProcesses(zj).Threads(n).BasePriority) .Add(myProcesses(zj).Threads(n).CurrentPriority) .Add(myProcesses(zj).Threads(n).PriorityLevel) .Add(myProcesses(zj).Threads(n).PrivilegedProcessorTime) .Add(myProcesses(zj).Threads(n).StartTime) .Add(myProcesses(zj).Threads(n).ThreadState.ToString) .Add(myProcesses(zj).Threads(n).TotalProcessorTime.Seconds) .Add(myProcesses(zj).Threads(n).UserProcessorTime.Seconds) .Add(myProcesses(zj).Threads(n).WaitReason.ToString) End With End Sub Private Sub ListBox5_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox5.DoubleClick ListBox6.Items.Clear() Dim f, n, m f = myProcesses(zj).Modules.Count n = ListBox5.SelectedIndex Label7.Text = "模块" & ListBox5.Items.Item(n) & "相关信息" With ListBox6.Items‘与进程相关的模块信息见System.Diagnostics. ProcessModule类,因为Processes.Modules属性是返回Modules对象数组而Modules对象数组的实例是由ProcessModule类来创建,Modules对象数组的信息是包含在System.Diagnostics. ProcessModule类中。 m = Hex(myProcesses(zj).Modules(n).BaseAddress.ToInt32)‘转换成16进制 .Add(m) m = Hex(myProcesses(zj).Modules(n).EntryPointAddress.ToInt32) .Add(m) .Add(myProcesses(zj).Modules(n).FileVersionInfo) .Add(myProcesses(zj).Modules(n).ModuleMemorySize) .Add(myProcesses(zj).Modules(n).ModuleName) End With End Sub |