I'm trying to read the registry from my c++ program, this works fine when I run it in 64-bit mode, but when I switch over to 32bit mode it does not. Now I've learned that there are 2 separate parts of the registry, the 64 and 32-bit parts. I read that I should use KEY_WOW64_64KEY but I can't figure out how. The following code is what i had:
char value[255];
DWORD BufferSize = BUFFER;
RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Cryptography", "MachineGuid", RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);
std::wcout << value << std::endl;
system("pause");
And it works fine, but when I switch over to 32bit, it doesn't. So I tried the following: replacing RRF_RT_ANY with the RRF_RT_ANY | KEY_WOW64_32KEY
char value[255];
DWORD BufferSize = BUFFER;
RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Cryptography", "MachineGuid", RRF_RT_ANY | KEY_WOW64_32KEY, NULL, (PVOID)&value, &BufferSize);
std::wcout << value << std::endl;
system("pause");
But this also doesn't work, what is the correct way to apply this?
It returns a value of "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ"
According to the documentation :
RRF_SUBKEY_WOW6464KEY
If lpSubKey is not NULL, open the subkey that lpSubKey specifies with the KEY_WOW64_64KEY access rights.
So you can modify the code as:
RegGetValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",L"MachineGuid", RRF_RT_ANY | RRF_SUBKEY_WOW6464KEY, NULL, (PVOID)&value, &BufferSize);
Then it works for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.