title: Why do I get an 'Invalid namespace' error when attempting to use WMI?
body: <p>I need to get the serial number of a hard drive to serve as a unique ID for user identification purposes, but however the program is crashing when I attempt to access the serial number:</p>
  <blockquote>
  <p>An unhandled exception of type 'System.Management.ManagementException' occurred in System.Management.dll</p>
  <p>Additional information: Invalid namespace</p>
  </blockquote>
  <p>I've looked around and there doesn't seem to be much on the issue; <a href="http://www.vbforums.com/showthread.php?459429-WMI-Invalid-Namespace-Error" rel="nofollow noreferrer">one website</a> mentions that 'WMI is like Death Valley', and I'm inclined to agree on this.</p>
  <p>The error is occurring at <code>moHD.[Get]()</code>.</p>
  <p>Why am I getting this error, and how can I fix it?</p>
  <p>The code:</p>
  <pre><code>Public Function getSerial(ByVal strDrive As String) As String 'Get HD Serial Number
      If strDrive = &quot;&quot; OrElse strDrive Is Nothing Then
          strDrive = &quot;C&quot;
      End If
      Dim moHD As New ManagementObject(&quot;Win32_LogicalDisk.DeviceID=&quot;&quot;&quot; + strDrive + &quot;:&quot;&quot;&quot;)
      moHD.[Get]()
      Return moHD(&quot;VolumeSerialNumber&quot;).ToString()
  End Function
  </code></pre>