title: Better way to run WMI queries?
body: <p>I do most of my scripting in VBScript and I often use WMI queries to get information from the system.  The WMI ExecQuery method always returns a WMI collection object that I have to access from a <code>For</code> loop -- even in cases where you could only ever possibly return one item.  Here is an example:</p>
  
  <pre><code>Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
  Set objColItems = objWMI.ExecQuery("SELECT * FROM Win32_BIOS",,48)
  
  For Each objItem In objColItems
      strManufacturer = objItem.Manufacturer
  Next
  
  ...
  </code></pre>
  
  <p>In this example, all I need is the brand of computer (i.e. Dell, HP, etc.).  There should only ever be one instance of the Win32_BIOS class.</p>
  
  <p>What's even more annoying, though, is when the class has multiple instances (say, <code>Win32_Printers</code> for example), and I know exactly which one I am looking for.  Then I have to insert an <code>If</code> to check the name.  It's an annoying amount of code when you're just looking for one piece of information from several classes.</p>
  
  <p>I thought I saw a code sample once upon a time where someone accessed a property directly from an instance of a WMI class with a single line of code, but of course I didn't write it down.</p>
  
  <p>So is there a way to do that without having to query for it and run it through a loop?</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>OK, I guess I just didn't Google hard enough, but I found out that what I am looking for is the <a href="http://msdn.microsoft.com/en-us/library/aa393868%28v=vs.85%29.aspx" rel="nofollow">SWbemServices.Get</a> method.  This allows you to get properties of a specific instance of a class without querying for it.</p>
  
  <p>In the example they provide on that page, I can get the status of a service with just two lines of code:</p>
  
  <pre><code>Set objWMI = GetObject("winmgmts:\\.\root\cimv2").Get("Win32_Service.Name='Spooler'")
  WScript.Echo objWMI.State
  </code></pre>
  
  <p>Neat.  Except it only works in cases where there are multiple instances of the class and you know which one you're after.  A good find, but how do I use it in the example I gave above, where there is only one instance?</p>
  
  <pre><code>Set objWMI = GetObject("winmgmts:\\.root\cimv2").Get("Win32_BIOS.Manufacturer")
  </code></pre>
  
  <p>Gives me an error: <code>Invalid object path.</code></p>
  
  <pre><code>Set objWMI = GetObject("winmgmts:\\.root\cimv2").Get("Win32_BIOS")
  </code></pre>
  
  <p>That line works, but it's not bound to an instance so all I get are nulls.</p>
  
  <p>How do I use this technique for single-instance classes?  Like is there a way to specify the "default" instance?</p>