首页 > 解决方案 > 在 Windows 2008(32 位)中无法读取同一分支下的某些注册表项

问题描述

我正在使用以下代码来读取注册表项的值。szValueName=L"Background"在分支下,我能够成功读取密钥的值"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"

但是,当我尝试szValueName=L"DefaultDomainName"在同一分支下读取该值时,RegOpenKeyEx()返回 0(ERROR_SUCCESS)并RegQueryValueEx()返回 2(ERROR_FILE_NOT_FOUND)。令人惊讶的是,能够使用 REG QUERY 命令从命令行读取这两个值。

int _tmain(int argc, _TCHAR* argv[])
{
    wchar_t buffer[MAX_PATH];
    wchar_t* szValueName;
    wchar_t* KeyName;
    HKEY hKey;
    DWORD dwBufLen;
    LONG lret;
    DWORD* reservedNULL = NULL;
    DWORD reservedZero = 0;

    szValueName = L"DefaultDomainName"; 
    KeyName = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon";
    lret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, reservedZero, KEY_READ, &hKey);
    if (lret == ERROR_SUCCESS)
    {
        dwBufLen = MAX_PATH;
        lret = RegQueryValueEx(hKey, szValueName, reservedNULL, NULL, (BYTE*)buffer, &dwBufLen);
        if (lret == ERROR_SUCCESS)
        {
           wcout << buffer << endl;
        } // end if successfull value read
        RegCloseKey(hKey);
    } // end if successfule key open

    return 0;
}

标签: winapiregistrywindows-server-2008

解决方案


推荐阅读