winapi - 在 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;
}
解决方案
推荐阅读
- r - R 的官员包无法识别主布局中的 Powerpoint 占位符
- swift - How to encode SecKey to base64 string using swift
- html - JQuery 自动完成永远不会触发
- opencv - Is it possible to find camera position using 8-10 non-coplanar points, if their 3D coordinates are unknown?
- vue.js - 在 Vue.js 模板的每个循环中显示 JSON 数据属性
- ios - Core Data Error when trying to save using a tuple
- javascript - Angularjs allowing the user to input only numbers and forward slash(/)
- python - Extract webscraped python data to SQLite, excel or xml?
- java - encrypted object serialization on android, cannot load from file
- python - 在您单击按钮之前,在 tkinter 中显示空图