无法读取C某些注册表项 [英] Unable to read certain registry keys in C

查看:205
本文介绍了无法读取C某些注册表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用RegOpenKeyEx()和函数RegQueryValueEx()来尝试并获得价值在Windows注册表中六个键。我能够做到这一点的六个四个,但我没有对某些人。

I'm using RegOpenKeyEx() and RegQueryValueEx() to try and get the value for six keys in the Windows registry. I'm able to do it for four of the six but am failing on certain others.

wchar_t * getRegKeyValue(HKEY rootKeyToGet, LPCWSTR subKeyToGet, LPCWSTR valueToGet)
{
    HKEY resultHKey = 0;
    wchar_t resultString[255] = L"";
    DWORD dwType = REG_SZ;
    DWORD resultSize = 255;

    // See if the subkey exists. If it does, get its value.
    if (RegOpenKeyEx(rootKeyToGet, subKeyToGet, NULL, KEY_ALL_ACCESS, &resultHKey) == ERROR_SUCCESS)
    {
        RegQueryValueEx(resultHKey, valueToGet, NULL, &dwType, (LPBYTE) &resultString, &resultSize);
    }

    RegCloseKey(resultHKey);
    resultHKey = NULL;

    RegCloseKey(rootKeyToGet);
    rootKeyToGet = NULL;

    return resultString;
}

以下是一些成功的呼叫:

The following are some successful calls:

swprintf(buffer, L"&ie=%s", getRegKeyValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Internet Explorer", L"Version"));

swprintf(buffer, L"&os=%s.", getRegKeyValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CurrentVersion"));

wcscat(url, getRegKeyValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CurrentBuild"));

不成功的调用示例:

Example of an unsuccessful call:

wcscpy(buffer, getRegKeyValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CSDVersion"));

我能够在呼叫不成功开关键,但该值的查询将返回一个空字符串。我在运行Visual Studio为管理员。一直在抓我的头对我要去的地方错了最后一天。

I'm able to open the key in the unsuccessful call but the query for that value returns an empty string. I'm running Visual Studio as an administrator. Have been scratching my head for the last day on where I am going wrong.

更新:code返回的ERROR_FILE_NOT_FOUND。在codeS最明确显示在注册表编辑器存在。

推荐答案

我想,你有32位进程和64位的机器。发生这种情况时,注册表重定向混淆的问题。尝试读取 HKLM \\ SOFTWARE \\ ... 重定向到 HKLM \\ SOFTWARE \\ Wow64Node \\ ... 。所以,你需要打开与 RegistryView 枚举注册表的64位视图。

I guess that you have a 32 bit process and a 64 bit machine. When this happens, registry redirection confounds matters. Attempts to read HKLM\Software\... get redirected to HKLM\Software\Wow64Node\.... So you need to open the 64 bit view of the registry with the RegistryView enumeration.

这篇关于无法读取C某些注册表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆