WMI Instrumentation

Vb.Net

Public Domain

This generates a managed class for WMI instrumentation.

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
   Public Function ListServices() As Dictionary(Of String, String)
    co = New ConnectionOptions()
    co.Username = My.Settings.Username
    co.Password = My.Settings.Password
    co.Impersonation = ImpersonationLevel.Impersonate
    scope = New ManagementScope("\\" + IPNumber + "\root\cimv2", co)
    Dim result As New Dictionary(Of String, String)
    Dim mc As New ManagementClass("Win32_Service")
    Dim oc As ManagementObjectCollection
    Dim query As New ObjectQuery
    query.QueryString = "SELECT * FROM Win32_Service"
    Dim mos As New ManagementObjectSearcher(scope, query)
    oc = mos.Get
    For Each item As ManagementObject In oc
      result.Add(item.Item("DisplayName"), item.Item("State"))
    Next
    Return result
  End Function