title: WMI - Directly accessing the singleton instance of Win32_OperatingSystem
body: <p>I've having trouble directly accessing the <strong>Win32_OperatingSystem</strong> management class that is exposed via WMI.</p>
  
  <p>It is a singleton class, and I'm pretty certain "Win32_OperatingSystem=@" is the correct path syntax to get the instance of a singleton.</p>
  
  <p>The call to InvokeMethod produces the exception listed at the bottom of the question, as does accessing the ClassPath property (commented line).</p>
  
  <p>What am I doing wrong?</p>
  
  <p>[I'm aware that I can use ManagementObjectSearcher/ObjectQuery to return a collection of Win32_OperatingSystem (which would contain only one), but since I know it is a singleton, I want to access it directly.]</p>
  
  <hr>
  
  <pre><code>ManagementScope cimv2 = InitScope(string.Format(@"\\{0}\root\cimv2", this.Name));
  
  ManagementObject os = new ManagementObject(
      cimv2,
      new ManagementPath("Win32_OperatingSystem=@"),
      new ObjectGetOptions());
  
  //ManagementPath p = os.ClassPath;
  
  os.InvokeMethod("Reboot", null);
  </code></pre>
  
  <hr>
  
  <p>System.Management.ManagementException was caught
    Message="Invalid object path "
    Source="System.Management"
    StackTrace:
    at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
    at System.Management.ManagementObject.Initialize(Boolean getObject)
    at System.Management.ManagementBaseObject.get_wbemObject()
    at System.Management.ManagementObject.get_ClassPath()
    at System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject&amp; inParameters, IWbemClassObjectFreeThreaded&amp; inParametersClass, IWbemClassObjectFreeThreaded&amp; outParametersClass)
    at System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args)</p>
  
  <hr>
  
  <p>Thanks for the replies.</p>
  
  <p><strong>Nick</strong> - I don't know how to go about doing that :)</p>
  
  <p><strong>Uros</strong> - I was under the impression that it was a singleton class because of <a href="http://msdn.microsoft.com/en-us/library/aa394239.aspx" rel="nofollow noreferrer">this</a> MSDN page. Also, opening the class in the WBEMTest utility shows <a href="http://img247.imageshack.us/img247/5686/64933271au3.png" rel="nofollow noreferrer">this</a>.</p>
  
  <hr>
  
  <p>The instances dialog shows: "1 objects" and "max. batch: 1" in those fields and lists "Win32_OperatingSystem=@"</p>
  
  <p>The ManagementScope is verified as working, so I don't know what's up. I'm a WMI novice, but this seems like one of the simplest use cases!</p>