title: How to get the product Version number which is stored in the Deployment Project?
body: <p>I have a WinForms application written in C#. There is a Deployment Project which creates a setup.exe and where I set a version number.</p>
  
  <p>How can I fetch this version number at runtime so that I can write it to a log or display it in the About box?</p>
  
  <p>I had been using the following code but it does not work for 64-bit installations.</p>
  
  <pre><code>RegistryKey key = Registry.LocalMachine.OpenSubKey(
          @"Software\Microsoft\Windows\CurrentVersion\Uninstall");
  string[] subKeyNames = key.GetSubKeyNames();
  
  foreach (string subKeyName in subKeyNames)
  {
      Microsoft.Win32.RegistryKey subKey2 = key.OpenSubKey(subKeyName);
  
      if (ValueNameExists(subKey2.GetValueNames(), "DisplayName") 
          &amp;&amp; ValueNameExists(subKey2.GetValueNames(), "DisplayVersion"))
      {
          string name = subKey2.GetValue("DisplayName").ToString();
          string version = subKey2.GetValue("DisplayVersion").ToString();
          if(name == "MyAppName") return version;
      }
      subKey2.Close();
  }
  key.Close();
  return "v?";
  </code></pre>