Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing frmProcessProps.vb (8.73 KB)
Option Explicit On
Imports System.Diagnostics
Public Class frmProcessProps
Private _thisProcess As Process = Nothing
Private _thisPriority As ProcessPriorityClass = Nothing
Private priorityList() As Integer = { _
ProcessPriorityClass.RealTime, _
ProcessPriorityClass.High, _
ProcessPriorityClass.AboveNormal, _
ProcessPriorityClass.Normal, _
ProcessPriorityClass.BelowNormal, _
ProcessPriorityClass.Idle _
}
Public Sub New(ByVal objWindow As clsWindowObject)
Me.New(objWindow.ProcessId)
End Sub
Public Sub New(ByVal processId As Integer)
Me.New(_getProcessById(processId))
End Sub
Public Sub New(ByVal objProcess As Process)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
_thisProcess = objProcess
End Sub
Private Shared Function _getProcessById(ByVal processId As Integer) As Process
Try
Return Process.GetProcessById(processId)
Catch
Return Nothing
End Try
End Function
Private Function _searchArray(ByVal intPriority As Integer) As Boolean
If intPriority = _thisPriority Then
Return True
Else
Return False
End If
End Function
Private Sub _showWaitCursor(ByVal bShow As Boolean)
' show/hide the hourglass
If bShow Then
Me.Cursor = Cursors.WaitCursor
Me.UseWaitCursor = True
Else
Me.UseWaitCursor = False
Me.Cursor = Cursors.Arrow
End If
End Sub
Private Sub frmProcessProps_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If _thisProcess Is Nothing Then
MessageBox.Show("Process not available.", Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Me.Close()
Exit Sub
End If
Me.Text += FormatHandle(_thisProcess.Id)
Try
' store the priority class
_thisPriority = _thisProcess.PriorityClass
Catch
' disable the priority class selection
cboPriority.Enabled = False
End Try
' general page
txtAssembly.Text = _thisProcess.ProcessName
cboPriority.SelectedIndex = Array.FindIndex(priorityList, AddressOf _searchArray)
cboPriority.Tag = False
linkProcessId.Text = FormatHandle(_thisProcess.Id)
Try
lblPriorityBase2.Text = _thisProcess.BasePriority.ToString
lblThreads2.Text = _thisProcess.Threads.Count.ToString("###,##0")
Catch
lblPriorityBase2.Text = "N/A"
lblThreads2.Text = "N/A"
End Try
Try
lblModules2.Text = _thisProcess.Modules.Count.ToString("###,##0")
lblHandles2.Text = _thisProcess.HandleCount.ToString("###,##0")
lblStartTime2.Text = _thisProcess.StartTime.ToString
lblCPUTime2.Text = _thisProcess.UserProcessorTime.ToString
lblUserTime2.Text = _thisProcess.UserProcessorTime.Add(_thisProcess.PrivilegedProcessorTime).ToString
lblPrivilegedTime2.Text = _thisProcess.PrivilegedProcessorTime.ToString
lblElapsedTime2.Text = _thisProcess.TotalProcessorTime.ToString
Catch
lblModules2.Text = "N/A"
lblStartTime2.Text = "N/A"
lblCPUTime2.Text = "N/A"
lblUserTime2.Text = "N/A"
lblPrivilegedTime2.Text = "N/A"
lblElapsedTime2.Text = "N/A"
btnUnload.Enabled = False
btnTerminate.Enabled = False
End Try
' memory page
lblVirtualSize2.Text = _thisProcess.VirtualMemorySize64.ToString("###,000") + " bytes"
lblPeakVirtualSize2.Text = _thisProcess.PeakVirtualMemorySize64.ToString("###,000") + " bytes"
lblWorkingSet2.Text = _thisProcess.WorkingSet64.ToString("###,000") + " bytes"
lblPeakWorkingSet2.Text = _thisProcess.PeakWorkingSet64.ToString("###,000") + " bytes"
lblPagedPoolSize2.Text = _thisProcess.PagedSystemMemorySize64.ToString("###,000") + " bytes"
lblVirtualSize2.Text = _thisProcess.NonpagedSystemMemorySize64.ToString("###,000") + " bytes"
lblPrivateSize2.Text = _thisProcess.PrivateMemorySize64.ToString("###,000") + " bytes"
' modules page
Try
For Each thisModule As ProcessModule In _thisProcess.Modules
With lvModules.Items.Add(thisModule.ModuleName)
.SubItems.Add(thisModule.ModuleMemorySize.ToString + " B")
.SubItems.Add(FormatHandle(thisModule.EntryPointAddress.ToInt32))
.ToolTipText = thisModule.FileName
.Tag = thisModule
If thisModule.ModuleName = _thisProcess.MainModule.ModuleName Then _
.Selected = True
End With
Next
Catch
lvModules.Enabled = False
End Try
' fileinfo page
Try
txtFileInfo.Text = _thisProcess.MainModule.FileVersionInfo.ToString
Catch
txtFileInfo.Enabled = False
End Try
btnApply.Enabled = False
End Sub
Private Sub lvModules_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvModules.DoubleClick
Dim objHitTest As ListViewHitTestInfo = lvModules.HitTest( _
lvModules.PointToClient(Control.MousePosition))
If lvModules.SelectedItems(0).Equals(objHitTest.Item) Then _
MessageBox.Show(objHitTest.Item.Tag.FileVersionInfo.ToString, _
objHitTest.Item.Tag.ModuleName, MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub cboPriority_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPriority.SelectedIndexChanged
cboPriority.Tag = True
btnApply.Enabled = True
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
btnApply.PerformClick()
Me.Close()
End Sub
Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click
If cboPriority.Tag Then
Try
' set the priority class
_thisProcess.PriorityClass = priorityList(cboPriority.SelectedIndex)
Catch ex As Exception
MessageBox.Show("Error: " + ex.Message, Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
btnApply.Enabled = False
End Sub
Private Sub btnUnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnload.Click
If MessageBox.Show("Are you sure you want to unload the main window?", _
Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
If _thisProcess.CloseMainWindow() Then
Me.Close()
Else
MessageBox.Show("Failure!", Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
End Sub
Private Sub btnTerminate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTerminate.Click
If MessageBox.Show("Are you sure you want to terminate this process?", _
Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Try
_thisProcess.Kill()
Me.Close()
Catch ex As Exception
MessageBox.Show("Failure!" + vbCrLf + vbCrLf + "Reason: " + ex.Message, _
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
Private Sub linkProcessId_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles linkProcessId.LinkClicked
_showWaitCursor(True)
With New frmProcessSpy(Nothing, _thisProcess)
.Show(Me)
End With
_showWaitCursor(False)
End Sub
End Class