title: Get device id in windows with c#
body: <p>I have a problem getting the id of the Windows device. He returns it to me empty. I don't know why that inconvenience.
  My code:</p>
  
  <pre><code>productIdEdit.Text = RegHelper.readStringValue(RegistryValues.productIdKey(), RegistryValues.productIdValue());
  </code></pre>
  
  <p>With this line I call two classes with the values I need to search for.
  RegHelper:</p>
  
  <pre><code>public static string readStringValue(string regKey, string regValue)
  {
  string result;
  try
  {
     result = (string)Registry.GetValue(regKey, regValue, "");
  }
  catch (Exception)
  {
      result = ""; 
  }
  return result;
  }
  </code></pre>
  
  <p>RegistryValues:</p>
  
  <pre><code>public static string productIdKey()
  {
      return "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
  }
  
  public static string productIdValue()
  {
      return "ProductId";
  }
  </code></pre>
  
  <p>The program runs in administrator mode.</p>