RegQueryInfoKey中的值不正确 [英] Incorrect values from RegQueryInfoKey

查看:109
本文介绍了RegQueryInfoKey中的值不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR:



- 在Win7 x64上运行32位代码

- 打开HKEY_CURRENT_USER \Software \Classes \ CLSID为KEY_ALL_ACCESS

- 使用除hKey和lpcSubKeys之外的所有内容调用RegQueryInfoKey NULL

- lpcSubKeys返回不正确的值(例如正确答案为2时为385,946,848)



详细信息:



在跟踪某些代码中的"挂起"时,我注意到RegQueryInfoKey似乎返回了奇怪的值(由procmon报道)。 虽然密钥一直在注册表中添加和删除,但在不到一秒钟内添加3.85亿个密钥似乎不太可能是




要跟踪此情况,我创建了一个简单的32位测试程序(下面),它只是在每次更改时打印出RegQueryInfoKey的lpcSubKeys的值(使用vs2010,debug,unicode构建)。 我启动此程序并在执行其他
任务时保持运行。 例如,启动应用程序(例如IE)会导致值发生巨大变化。  
$


一条重要线索:更改对RegQueryInfoKey的调用也返回lpcMaxClassLen会导致lpcSubKeys正确无误。 这让我相信问题不在于添加(和删除)大量密钥,而是实际上存在
RegQueryInfoKey的问题。

TLDR:

- Running 32bit code on Win7 x64
- Opening HKEY_CURRENT_USER\Software\Classes\CLSID as KEY_ALL_ACCESS
- Calling RegQueryInfoKey with all except hKey and lpcSubKeys NULL
- lpcSubKeys returns incorrect values (for example 385,946,848 when the correct answer is 2)

Details:

While tracking down a 'hang' in some code, I noticed that RegQueryInfoKey seemed to be returning weird values (as reported by procmon).  While keys get added and removed from the registry all the time, adding 385 million keys in less than a second seemed unlikely.

To track this down, I created a simple 32bit test program (below) that just prints out the value of RegQueryInfoKey's lpcSubKeys every time it changes (built with vs2010, debug, unicode).  I start this program and leave it running while performing other tasks.  For example launching applications (such as IE) causes the value to change wildly.  

And one important clue: Changing the call to RegQueryInfoKey to also return lpcMaxClassLen results in lpcSubKeys being correct.  This makes me believe that the problem isn't that something is adding (and removing) vast numbers of keys, but that there is in fact a problem with RegQueryInfoKey.

请注意,由于这是x64上的32位应用,因此HKEY_CURRENT_USER \Software \Classes \ CLSID会映射到  。HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID 那可能很重要? 或者因为这是一个常用的密钥,它会以某种方式缓存
(procmon表明它是)?

Note that since this is a 32bit app on x64, HKEY_CURRENT_USER\Software\Classes\CLSID gets mapped to  HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID.  That might be important?  Or maybe since this is a commonly used key, it gets cached somehow (procmon suggests that it is)?

这是我的测试代码:



Here's my test code:

#include <stdio.h>
#include <Windows.h>

int main()
{
  HKEY h;
  LONG l;
  DWORD old, lpcSubKeys, lpcMaxClassLen;

  old = 0xffffffff;

  l = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Classes\\CLSID", 0, KEY_ALL_ACCESS, &h);
  if (l != ERROR_SUCCESS)
  {
    printf("Can't open key\n");
    return 0;
  }

  do {
    Sleep(5);

#if 1
    // Broken
    l = RegQueryInfoKey(h, NULL, NULL, NULL, &lpcSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
#else
    // Works
    l = RegQueryInfoKey(h, NULL, NULL, NULL, &lpcSubKeys, NULL, &lpcMaxClassLen, NULL, NULL, NULL, NULL, NULL);
#endif

    if (l != ERROR_SUCCESS)
    {
      printf("RegQueryInfoKey failed\n");
      return 0;
    }

    if (lpcSubKeys != old)
    {
      printf("Keys: %x\n", lpcSubKeys);
      old = lpcSubKeys;
    }
  } while (true);

  return 0;
}

注册表代码中的错误似乎不太可能,但我不知道是什么否则这可能是。 任何线索都欢迎。 如果有人能够重复这一点,那也很有用。

A bug in the registry code seems unlikely, but I don't know what else this could be.  Any clues welcome.  And if someone is able to repro this, that would be good to know too.

推荐答案

感谢您抽出宝贵时间。

Thank you for taking the time.

由于你的帖子,我开始更新我的一些VirtualBox图像,看看我是否可以重现其他版本的行为。 花了一段时间。 由于我不经常使用VirtualBox,我的版本已经过时了。

As a result of your post, I started updating some of my VirtualBox images to see if I could reproduce the behavior on other versions.  It took a while.  Since I don't use VirtualBox often, my version was out of date.

不幸的是(或者幸运的是?),当我完成VirtualBox的更新时,更新所有客户操作系统中的访客添加,测试其他操作系统,创建Win7映像并应用所有补丁等,我的问题从主机操作系统中消失。

Unfortunately (or perhaps fortunately?), by the time I finished updating VirtualBox, updating the guest additions in all the guest OSs, testing other OSs, creating a Win7 image and applying all the patches, etc, my problem disappeared from the host OS.

Argh!

经过几天能够随意产生问题(即使重新启动),现在我根本无法做到这一点。 我最好的猜测是(不知何故)旧的VirtualBox驱动程序正在捣乱,并在我更新时得到修复? 

After days of being able to produced the problem at will (even through reboots), now I can't do it at all.  My best guess is that (somehow) the old VirtualBox drivers were mucking something up and it got fixed when I updated? 

公平地说,我没有任何具体证据表明VirtualBox。 我正在做其他事情,所以也许只是巧合。 如果我记得我之前的VirtualBox版本到底是什么版本,我很想回去看看我是否可以重现
,但我没有。 

To be fair, I have no specific evidence indicting VirtualBox.  I was doing other things, so perhaps it was just a coincidence.  If I remembered exactly what version of VirtualBox I had before, I'd be tempted to go back and see if I could reproduce it, but I don't. 

虽然不知道实际问题是什么并不令人满意,但我想我只会取胜。

While it's unsatisfying to not know what the actual problem was, I guess I'll just take the win.


这篇关于RegQueryInfoKey中的值不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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