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,
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.