Generate a managed class for WMI instrumentation

So,I need a list of services from a remote machine for an application I am building for Wendys.  I wrote a boatload of System.Management code to do it, liike something like this:

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

 

Then what did I learn?  Lo and behold, there is a Tool To Do This.  I hate it when that happens!  Just pass in the WMI namespace and it will generate all the class code you can eat.  (Win32_Battery made me 2800 lines of code).  Check it out here on MSDN.

Who the heck is Bill Sempf?

Bill Sempf

Husband. Father. Author. Software composer. Brewer. Lockpicker. Ninja. Insurrectionist. Honorary blue teamer. Lumberjack. All words that have been used to describe me recently. I have written some books, and software.

I'm speaking at Black Hat Europe

TextBox

INETA Community Speakers Program

TextBox

profile for Bill Sempf on Stack Exchange, a network of free, community-driven Q&A sites

EFF Member 2013

Month List

TextBox

Paying the bills

 

TextBox