c++registrywindows-7-x64windows-7-embedded

RegOpenKeyExW with HKEY_LOCAL_MACHINE returns 2 on Windows Embedded 7 64 bit


I need to read key values in HKEY_LOCAL_MACHINE\SOFTWARE from my application. I use the following snippet to do that but it always returns 2.

std::wstring strTmp;
strTmp = L"SOFTWARE\\TEMP";
RegOpenKeyExW(HKEY_LOCAL_MACHINE, strTmp.c_str(), 0, KEY_READ, &hKey))

But when I use HKEY_CURRENT_USER then I'm able to read information successfully from HKEY_CURRENT_USER\SOFTWARE. I understand that my application is unable to read from HKEY_LOCAL_MACHINE due to access privileges. I did run my application with administrator privileges (using Run As) but that did not help me out.

Can someone shed some light on how can I access the HKEY_LOCAL_MACHINE using RegOpenKeyExW.

I did go through the links 1, 2 but that did not help me out,


Solution

  • My apologies for my misunderstandings. Actually I had to use KEY_WOW64_32KEY flag instead of KEY_WOW64_64KEY in RegOpenKeyExW(HKEY_LOCAL_MACHINE, strTmp.c_str(), 0, KEY_READ | KEY_WOW64_32KEY, &hKey)) to get my application working. Thanks to Mohamad Elghawi.