Solved

vb.net and wmi process list query

Posted on 2014-11-01
4
319 Views
Last Modified: 2014-11-01
I use the below code to return processes to a listview, i am trying to use a group header and no matter what i do it wont show up:

What am i doing wrong?

For Each managementObject As ManagementObject In (New ManagementObjectSearcher(theScope, objectQuery)).[Get]()
                Dim item As ListViewItem = ListView2.Items.Add(managementObject("ProcessId").ToString())
                item.SubItems.Add(managementObject("Name").ToString())
                item.Group = ListView2.Groups("Process List")
                'ListView2.Items.Add(item)
            Next

Open in new window

0
Comment
Question by:derek7467
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:it_saige
Comment Utility
What does not show up, the items or the group header?

-saige-
0
 
LVL 32

Accepted Solution

by:
it_saige earned 500 total points
Comment Utility
Here is an example:
Imports System
Imports System.Management

Public Class Form1
	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Try
			Dim scope As New ManagementScope("root\CIMV2")
			Dim query As New ObjectQuery("Select * from Win32_Process")
			Dim item As ListViewItem = Nothing
			ListView1.Groups.Add(New ListViewGroup("Processes", "Process List"))
			For Each managementObject As ManagementObject In (New ManagementObjectSearcher(scope, query)).[Get]()
				item = New ListViewItem(managementObject("ProcessId").ToString())
				item.SubItems.Add(managementObject("Name").ToString())
				item.Group = ListView1.Groups("Processes")
				If Not item Is Nothing Then
					ListView1.Items.Add(item)
				End If
				item = Nothing
			Next
			ListView1.ShowGroups = True
		Catch ex As Exception
			MsgBox(ex.ToString)
		End Try
	End Sub
End Class

Open in new window


Produces the following output:Capture.JPG
-saige-
0
 

Author Comment

by:derek7467
Comment Utility
Group header is missing I'll try your example. Thanks!
0
 

Author Closing Comment

by:derek7467
Comment Utility
that worked, thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now