简体   繁体   English

从 32 位 c++ 程序读取 64 位注册表?

[英]Reading 64bit registry from 32bit c++ program?

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.我正在尝试从我的 c++ 程序中读取注册表,当我在 64 位模式下运行它时它工作正常,但是当我切换到 32 位模式时它不会。 Now I've learned that there are 2 separate parts of the registry, the 64 and 32-bit parts.现在我了解到注册表有 2 个独立的部分,即 64 位和 32 位部分。 I read that I should use KEY_WOW64_64KEY but I can't figure out how.我读到我应该使用 KEY_WOW64_64KEY 但我不知道如何。 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.它工作正常,但是当我切换到 32 位时,它就不行了。 So I tried the following: replacing RRF_RT_ANY with the RRF_RT_ANY |所以我尝试了以下方法:将 RRF_RT_ANY 替换为 RRF_RT_ANY | KEY_WOW64_32KEY 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 "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ" It returns a value of "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ"

According to the documentation :根据文档

RRF_SUBKEY_WOW6464KEY RRF_SUBKEY_WOW6464KEY

If lpSubKey is not NULL, open the subkey that lpSubKey specifies with the KEY_WOW64_64KEY access rights.如果 lpSubKey 不是 NULL,则使用 KEY_WOW64_64KEY 访问权限打开 lpSubKey 指定的子密钥。

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.然后它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM