I'm trying to display all services on a computer into column 1 under Processes and column 2 as services. I can't figure out how to do this with the WMI statements. Please Help! Thanks!

Here is my code......

Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click

Try
Dim connection As New ConnectionOptions

connection.Username = userNameBox.Text
connection.Password = passwordBox.Text
connection.Authority = "ntlmdomain:rljoc.com"

Dim scope As New ManagementScope( _
"\\localhost\root\CIMV2")
scope.Connect()

Dim query As New ObjectQuery("SELECT * FROM Win32_Process")
Dim query1 As New ObjectQuery("SELECT * FROM Win32_OperatingSystem")
Dim query2 As New ObjectQuery("SELECT * FROM Win32_ComputerSystem")
Dim query3 As New ObjectQuery("SELECT * FROM Win32_Processor")
Dim query4 As New ObjectQuery("SELECT * FROM Win32_CDROMDrive")
Dim query5 As New ObjectQuery("SELECT * FROM Win32_DiskDrive")
Dim query6 As New ObjectQuery("SELECT * FROM Win32_BaseBoard")
Dim query7 As New ObjectQuery("SELECT * FROM Win32_Service")

Dim searcher As New ManagementObjectSearcher(scope, query)
Dim searcher1 As New ManagementObjectSearcher(scope, query1)
Dim searcher2 As New ManagementObjectSearcher(scope, query2)
Dim searcher3 As New ManagementObjectSearcher(scope, query3)
Dim searcher4 As New ManagementObjectSearcher(scope, query4)
Dim searcher5 As New ManagementObjectSearcher(scope, query5)
Dim searcher6 As New ManagementObjectSearcher(scope, query6)
Dim searcher7 As New ManagementObjectSearcher(scope, query7)
Dim queryObj1 As New ManagementObject
Dim queryObj As New ManagementObject
Dim blah As ListViewItem
Dim blah1 As ListViewItem.ListViewSubItem

For Each queryObj In searcher.Get()
blah = ListView1.Items.Add((queryObj("Caption")))
Next
For Each queryObj1 In searcher7.Get()
blah.SubItems.Add((queryObj1("Caption")))

Next


Dim SP As UInt16

For Each queryObj In searcher1.Get()

Label1.Text = (queryObj("Caption"))
SP = (queryObj("ServicePackMajorVersion"))
Label2.Text = "Service Pack " & SP.ToString
Next

Dim TotalPhysMem As UInt64

For Each queryObj In searcher2.Get()
TotalPhysMem = (queryObj("TotalPhysicalMemory"))

Label5.Text = TotalPhysMem.ToString
Next

For Each queryObj In searcher3.Get()
Dim test As String
Dim test1 As UInt32

test1 = (queryObj("NumberOfCores".ToString))
If test1.ToString = 2 Then
test = "Dual Core "
Label6.Text = test & (queryObj("Name"))
End If

Next

For Each queryObj In searcher4.Get()

Label7.Text = (queryObj("Caption"))
Next

For Each queryObj In searcher5.Get()

Label4.Text = (queryObj("Caption"))
Next

For Each queryObj In searcher6.Get()

Label3.Text = (queryObj("Product"))
Next

Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
Catch unauthorizedErr As System.UnauthorizedAccessException

MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message)
End Try
End Sub


Private Sub closeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeButton.Click

Close()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListView1.Columns.Add("Processes", 80, HorizontalAlignment.Left)
ListView1.Columns.Add("Services", 80, HorizontalAlignment.Left)
ListView1.Columns.Add("Title", 80, HorizontalAlignment.Left)
ListView1.Columns.Add("Salary", 80, HorizontalAlignment.Left)
ListView1.Columns.Add("Department", 80, HorizontalAlignment.Left)
End Sub

End Class

Comments
Use code tags.

Use code-tag to post source code. I am bit confused after reading "Salary" and "Department" label as the columns of ListView. Please elaborate your question.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  ListView1.Columns.Add("Processes", 80, HorizontalAlignment.Left)
  ListView1.Columns.Add("Services", 80, HorizontalAlignment.Left)
  ListView1.Columns.Add("Title", 80, HorizontalAlignment.Left)
  ListView1.Columns.Add("Salary", 80, HorizontalAlignment.Left)
  ListView1.Columns.Add("Department", 80, HorizontalAlignment.Left)
End Sub

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Take the windows task manager as an example. It has the Processes listed in column 1 and the list of users using that process in column 2. I want the list of processes in column 1(which I have that working) and the list of services in column 2 where the users would be. The "Title, Salary, and Department" are there for testing purposes. I hope that elaborates a little more.

This article has been dead for over six months. Start a new discussion instead.