We help IT Professionals succeed at work.
Get Started

vb.net - List remote processes and get description of process

fruitloopy asked
Last Modified: 2015-12-23
I have put together some code that gathers the running processes of a remote computer but I would like it to also get the description of the process. I.e. Iexplore.exe = Internet Explorer.

Here's my code so far:
Imports System.Diagnostics
Imports System.Collections

Public Class Processes
    Private Sub Processes_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim Process As New Process()
        Dim Count As Integer = 0
        For Each Process In Process.GetProcesses(Main.txtHostName.Text)
            On Error Resume Next
            ListView1.Items(Count).SubItems.Add(FormatNumber(Math.Round(Process.PrivateMemorySize64 / 1024), 0))
            Count += 1
            AddHandler Me.ListView1.ColumnClick, AddressOf ColumnClick
        ToolStripStatusLabel1.Text = "Processes: " & ListView1.Items.Count
    End Sub

    'Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
    '    For Each Process As ListViewItem In ListView1.SelectedItems
    '        System.Diagnostics.Process.GetProcessById(Process.SubItems(3).Text).Kill()
    '    Next
    '    Processes_Load(Nothing, Nothing)
    'End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Processes_Load(Nothing, Nothing)
    End Sub

    ' ColumnClick event handler. 
    Private Sub ColumnClick(ByVal o As Object, ByVal e As ColumnClickEventArgs)
        ' Set the ListViewItemSorter property to a new ListViewItemComparer 
        ' object. Setting this property immediately sorts the 
        ' ListView using the ListViewItemComparer object. 

        'Change this based on which direction you want
        Dim blnAscending As Boolean = True
        Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column, blnAscending)
    End Sub

    ' Implements the manual sorting of items by columns. 
    Class ListViewItemComparer
        Implements IComparer

        Private col As Integer
        Private AscOrder As Boolean

        Public Sub New()
            col = 0
            AscOrder = True
        End Sub

        Public Sub New(ByVal column As Integer, ByVal Ascending As Boolean)
            col = column
            AscOrder = Ascending
        End Sub

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
            Implements IComparer.Compare
            If AscOrder Then
                Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
                Return [String].Compare(CType(y, ListViewItem).SubItems(col).Text, CType(x, ListViewItem).SubItems(col).Text)
            End If
        End Function
    End Class

End Class

Open in new window

It would be great to also End the process remotely and refresh the results if that's possible?

I'm learning vb.net as I'm working on this project so please keep it simple for me!
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE