Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleList system process information similar to the information provided by Task Manager in Visual Basic .NET
DescriptionThis example shows how to list system process information similar to the information provided by Task Manager in Visual Basic .NET.
Keywordsprocess information, processes, Task Manager, Visual Basic .NET, VB.NET
CategoriesWindows
 
First, add a reference to System.Management.

When the program loads, it creates a ManagementSearcherObject to execute the query "SELECT * FROM Win32_process." It loops through the results saving the returned ManagementObjects and adding their captions to a list box.

 
Private m_Results As List(Of ManagementObject)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    m_Results = New List(Of ManagementObject)

    Dim searcher As New ManagementObjectSearcher("SELECT * " & _
        "FROM Win32_process")
    For Each result As ManagementObject In searcher.Get()
        lstCaptions.Items.Add(result.Item("Caption"))

        m_Results.Add(result)
    Next result
End Sub
 
When you select an item from the list box, the program call subroutine ShowDetail. This routine looks up the returned ManagementObject and displays its textual value in an appropriate format. Use the program's option buttons to pick the format.
 
' Show the detail for the selection.
Private Sub ShowDetail()
    If lstCaptions.SelectedIndex < 0 Then Exit Sub

    Dim result As ManagementObject = _
        m_Results.Item(lstCaptions.SelectedIndex)

    Dim txt As String
    If radMof.Checked Then
        txt = result.GetText(TextFormat.Mof).ToString()
    ElseIf radCimDtd20.Checked Then
        txt = result.GetText(TextFormat.CimDtd20).ToString()
    Else
        txt = result.GetText(TextFormat.WmiDtd20).ToString()
    End If

    txt = txt.Replace(vbLf, vbCrLf)
    txt = txt.Trim()
    txtDetails.Text = txt
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated