Solved

vb.net and wmi process list query

Posted on 2014-11-01
4
334 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 33

Expert Comment

by:it_saige
ID: 40417310
What does not show up, the items or the group header?

-saige-
0
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40417321
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
ID: 40417364
Group header is missing I'll try your example. Thanks!
0
 

Author Closing Comment

by:derek7467
ID: 40417403
that worked, thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

947 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

23 Experts available now in Live!

Get 1:1 Help Now