title: How to SELECT a single field from a Win32 WMI class?
body: <p><a href="https://msdn.microsoft.com/en-us/library/aa394084(v=vs.85).aspx" rel="nofollow noreferrer">Win32 Classes</a> in Windows OS are groups of <a href="https://docs.microsoft.com/en-us/windows/desktop/CIMWin32Prov/computer-system-hardware-classes" rel="nofollow noreferrer">Hardware</a>, Software or OS <a href="https://docs.microsoft.com/en-us/windows/desktop/WmiSdk/wmi-classes" rel="nofollow noreferrer">classes</a> (along with others) that contains features and attributes depending on the class selected. My problem is with the <a href="https://docs.microsoft.com/en-us/windows/desktop/CIMWin32Prov/win32-cdromdrive" rel="nofollow noreferrer">Win32_CDROMDrive</a> that has many properties of the connected ODD device like <code>Caption</code>, <code>Description</code>, <code>Drive</code>, <code>Id</code>, <code>Name</code>, etc.). The problem (specifically) is with the property <code>SerialNumber</code> which returns the identifier of the drive by the manufacture. <strong>It returns a null</strong> in a case <strong>and returns an actual value</strong> in a different case! The code will walk you through:</p>
  
  <p>Here is how to list all the properties of the <code>Win32_CDROMDrive</code> (<code>SerialNumber</code> exist with an actual value).</p>
  
  <pre><code>var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_CDROMDrive");
  foreach (ManagementObject mo in searcher.Get())
      foreach (PropertyData pd in mo.Properties)
          Console.WriteLine("{0}:- {1}", pd.Name, pd.Value);
  </code></pre>
  
  <p>To get a single property value (like <code>Name</code>) from the same class the query is changed to (and it will return the value of <code>Name</code>).</p>
  
  <pre><code>var searcher = new ManagementObjectSearcher("SELECT Name FROM Win32_CDROMDrive");
  </code></pre>
  
  <p>To get the value of the <code>SerialNumber</code> property the query is changed to (and here is the problem, it will return <strong>null</strong> while <strong>did not before</strong>!)</p>
  
  <pre><code>var searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_CDROMDrive");
  </code></pre>
  
  <p>More odd behavior is when I try to get the value of a property with other random one like this (it will return actual values for both <code>Name</code> and <code>SerialNumber</code>)</p>
  
  <pre><code>var searcher = new ManagementObjectSearcher("SELECT SerialNumber, SCSIPort FROM Win32_CDROMDrive");
  </code></pre>
  
  <p>While if with a property with a different initial (it will return <strong>null</strong> for the <code>SerialNumber</code> and actual value for the <code>Name</code>)</p>
  
  <pre><code>var searcher = new ManagementObjectSearcher("SELECT SerialNumber, Name FROM Win32_CDROMDrive");
  </code></pre>
  
  <p>I know I’ve asked a similar <a href="https://stackoverflow.com/questions/51189508/how-come-the-serialnumber-property-of-the-win32-cdromdrive-class-returns-nul">question</a> but I can’t delete it or edit it to this one (which what I have got so far) cause it has good information that might be helpful for someone (even if it is simple).</p>
  
  <p>I just want to get the <code>SerialNumber</code> solely like this <code>SELECT SerialNumber FROM Win32_CDROMDrive</code> without extracting the whole values and choosing between them.</p>