title: C++ get windows product id from registry
body: <p>I already searched the internet and found a lot of "solutions" which dont work for me :/</p>
  
  <p>I have this:</p>
  
  <pre><code>HKEY keyHandle;
  char rgValue[1024];
  char fnlRes[1024];
  DWORD size1;
  DWORD Type;
  
  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_QUERY_VALUE | KEY_WOW64_64KEY, &amp;keyHandle) == ERROR_SUCCESS)
  {
      size1 = 1023;
      RegQueryValueEx(keyHandle, L"Productid", NULL, &amp;Type, (LPBYTE)rgValue, &amp;size1);
      sprintf_s(fnlRes, "Product ID of your Windows system is:: %s", rgValue);
  }
  else strcpy_s(fnlRes, "Couldn't access system information!");
  
  RegCloseKey(keyHandle);
  
  std::cout &lt;&lt; fnlRes;
  </code></pre>
  
  <p>And I get this in console:</p>
  
  <p><a href="https://i.stack.imgur.com/QBzX0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QBzX0.png" alt="Screenshot"></a></p>