Link to home
Avatar of fruitloopy

asked on - List remote processes and get description of process

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 as I'm working on this project so please keep it simple for me!
Avatar of Gottler

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of fruitloopy


Thanks Gottler. That code would only gather the info for Iexplore.exe though.
How do I change my code above to fetch the description of every process gathered from the remote machine and place it into a listview column?
User generated image