Avatar of fruitloopy
 asked on

vb.net - 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 vb.net as I'm working on this project so please keep it simple for me!
.NET Programming

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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?
Populate each process description in the Description column
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck