[英]Cannot read Registry entry in C++
I have a registry entry I can't seem to read in C++, but it shows up in Regedit
. 我有一个我似乎无法在C ++中阅读的注册表项,但它出现在Regedit
。
Using the following C++ snippet: 使用以下C ++代码段:
openResult=RegOpenKeyEx( HKEY_LOCAL_MACHINE, _TEXT("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full"), 0, KEY_READ, &root);
readResult1=RegQueryValueEx(root, _TEXT("InstallPath"), NULL, NULL, data1, &size);
readResult2=RegQueryValueEx(root, _TEXT("fake_entry"), NULL, NULL, data2, &size);
I get Error 2, ERROR_FILE_NOT_FOUND
for my second RegQueryValueEx()
call. 我的第二个RegQueryValueEx()
调用得到错误2, ERROR_FILE_NOT_FOUND
。
As you can see in the image below, my fake_entry
exists. 如下图所示,我的fake_entry
存在。
I created this entry via Regedit
. 我通过Regedit
创建了这个条目。
Microsoft's Registry Keys Affected by WOW64 does not include the location I'm trying to read, and as you can see in the picture below, my fake_entry
is not in the Wow6432Node
location. 受WOW64影响的 Microsoft 注册表项不包括我正在尝试阅读的位置,如下图所示,我的fake_entry
不在Wow6432Node
位置。
fake_entry
doesn't work. 当我调试我的代码时,我偶然发现了这一点,我很好奇为什么我添加的fake_entry
不起作用。 fake_entry
at SOFTWARE\\\\Wow6432Node\\\\Microsoft\\\\NET Framework Setup\\\\NDP\\\\v4\\\\Full
with the same error. 是的,我尝试在SOFTWARE\\\\Wow6432Node\\\\Microsoft\\\\NET Framework Setup\\\\NDP\\\\v4\\\\Full
读取fake_entry
并出现相同的错误。 Running Windows 7, 64 bit, C++ in Visual Studio 2010, using ASCII character encoding. 使用ASCII字符编码在Visual Studio 2010中运行Windows 7,64位,C ++。
Am I misunderstanding the Registry Redirector? 我误解了注册表重定向器吗? Is there a problem with my code? 我的代码有问题吗? Are there some sort of permission settings on certain portions of the Registry? 注册表的某些部分是否有某种权限设置? I'm obviously missing something. 我显然错过了一些东西。 Please point me in the right direction. 请指出我正确的方向。
Try 尝试
openResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _TEXT("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full"), 0, KEY_READ|KEY_WOW64_64KEY, &root);
according to MSDN you should use either KEY_WOW64_64KEY
or KEY_WOW64_32KEY
for WOW64 access 根据MSDN,你应该使用KEY_WOW64_64KEY
或KEY_WOW64_32KEY
进行WOW64访问
You are misreading the table of keys affected by WOW64. 您误读了受WOW64影响的密钥表。 From the very top of that page: 从该页面的顶部:
The following table lists registry keys that are redirected, shared by both 32-bit and 64-bit applications, or redirected and reflected on 64-bit Windows. 下表列出了重定向,由32位和64位应用程序共享或在64位Windows上重定向和反映的注册表项。 Subkeys of the keys in this table inherit the parent key's behavior unless otherwise specified. 除非另行指定,否则此表中键的子键继承父键的行为。 If a key has no parent listed in this table, the key is shared. 如果密钥没有在此表中列出父密钥,则密钥将被共享。
The parent of your key is HKLM\\Software which is redirected. 您的密钥的父级是HKLM \\ Software,它被重定向。 So your key is also redirected. 所以你的密钥也被重定向了。 It inherits that from its parent, as the documentation that I quoted explains. 它从其父级继承,正如我引用的文档所解释的那样。
You'll need to read the 64 bit view using KEY_WOW64_64KEY. 您需要使用KEY_WOW64_64KEY读取64位视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.