A simple "Process Manager"
Posted: Sun Dec 27, 2009 12:57 am
Hi everyone i was bored last night and i wanted to know how to do stuff with system process etc.. i learnt so i may as well share my little knowledge with you... its not that handy tho some of you might find some of the code helpful :P enjoy
The program detects another instance of itself, it can search to see if a process by a name is running, see information about a selected process and finely kill a process.
![Image]()
The program detects another instance of itself, it can search to see if a process by a name is running, see information about a selected process and finely kill a process.

Code: Select all
Public Class Main
Public Sub New()
InitializeComponent()
UpdateProcessList()
End Sub
Private Sub UpdateProcessList()
Try
ProcessList.Items.Clear()
Info.Text = ""
Dim p As System.Diagnostics.Process
For Each p In System.Diagnostics.Process.GetProcesses()
ProcessList.Items.Add(p.ProcessName)
Next
ProcessList.Sort()
tslProcessCount.Text = "Processes running: " & ProcessList.Items.Count.ToString()
Catch ex As Exception
MsgBox("An error occured while trying to retrieve process list.")
End Try
End Sub
Private Sub btnUpdateProcessList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateProcessList.Click
UpdateProcessList()
End Sub
Private Sub btnKill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKill.Click
Try
If SelectedProcess.Text = Nothing Then
MsgBox("Click on a process name to select it.")
Else
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName(SelectedProcess.Text)
For Each p As Process In pProcess
p.Kill()
Next
UpdateProcessList()
End If
Catch ex As Exception
MsgBox("An error occured while trying to kill process.")
End Try
End Sub
Private Sub ProcessList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProcessList.SelectedIndexChanged
Dim PROCESSNAME As String = ProcessList.FocusedItem.ToString
PROCESSNAME = Replace(PROCESSNAME, "ListViewItem: {", "")
PROCESSNAME = Replace(PROCESSNAME, "}", "")
SelectedProcess.Text = PROCESSNAME
Try
Dim p As System.Diagnostics.Process
For Each p In System.Diagnostics.Process.GetProcessesByName(PROCESSNAME)
Info.Text = "ProcessName: " & p.ProcessName & vbNewLine
Info.Text = Info.Text & "ProcessID: " & p.Id & vbNewLine
Info.Text = Info.Text & "Responding: " & p.Responding & vbNewLine
Info.Text = Info.Text & "BasePriority: " & p.BasePriority & vbNewLine
Info.Text = Info.Text & "EnableRaisingEvents: " & p.EnableRaisingEvents & vbNewLine
Info.Text = Info.Text & "HandleCount: " & p.HandleCount & vbNewLine
Info.Text = Info.Text & "MainWindowTitle: " & p.MainWindowTitle & vbNewLine
Info.Text = Info.Text & "NonpagedSystemMemorySize: " & p.NonpagedSystemMemorySize & vbNewLine
Info.Text = Info.Text & "PagedMemorySize: " & p.PagedMemorySize & vbNewLine
Info.Text = Info.Text & "PagedSystemMemorySize: " & p.PagedSystemMemorySize & vbNewLine
Info.Text = Info.Text & "PeakPagedMemorySize: " & p.PeakPagedMemorySize & vbNewLine
Info.Text = Info.Text & "PeakVirtualMemorySize: " & p.PeakVirtualMemorySize & vbNewLine
Info.Text = Info.Text & "PeakWorkingSet: " & p.PeakWorkingSet & vbNewLine
Info.Text = Info.Text & "PrivateMemorySize: " & p.PrivateMemorySize & vbNewLine
Info.Text = Info.Text & "SessionId: " & p.SessionId & vbNewLine
Info.Text = Info.Text & "VirtualMemorySize: " & p.VirtualMemorySize & vbNewLine
Info.Text = Info.Text & "WorkingSet: " & p.WorkingSet
Next
Catch ex As Exception
Info.Text = "An error occured while tyring to retrive infomation."
End Try
End Sub
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
MsgBox("Another instance of the program is currently running!")
Else
End If
End Sub
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
If System.Diagnostics.Process.GetProcessesByName(SelectedProcess.Text).Count > 0 Then
MsgBox("A process by the name of " & SelectedProcess.Text & " is currently running!")
ElseIf SelectedProcess.Text = Nothing Then
MsgBox("No process name found!")
Else
MsgBox("No process by the name of " & SelectedProcess.Text & " is currently running")
End If
End Sub
End Class