【问题标题】:Can't load 64-bit key using RegLoadKey in 32-bit service无法在 32 位服务中使用 RegLoadKey 加载 64 位密钥
【发布时间】:2012-12-19 06:07:30
【问题描述】:

我需要从 32 位服务中打开并修改用户的注册表项(请注意,当时用户未登录。)我执行以下操作:

//For simplicity error checks are not shown
//I also made sure to enable the following privileges:
// SE_RESTORE_NAME, SE_BACKUP_NAME

//"ntuser.dat" = is the file OS uses to load user's profile
if(RegLoadKey(HKEY_LOCAL_MACHINE, L"Test123", L"C:\\Users\\UserA\\ntuser.dat") == ERROR_SUCCESS)
{
    HKEY hKey;
    DWORD dwRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
        L"Test123\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\TrayNotify"),
        NULL, KEY_READ | KEY_WOW64_64KEY, &hKey);

    //'dwRes' = is returned as 2, or ERROR_FILE_NOT_FOUND

    RegUnLoadKey(HKEY_LOCAL_MACHINE, L"Test123");
}

问题是Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify 键未加载,即使我知道它存在于实际的用户配置文件中。我可以通过加载用户帐户和使用 64 位 regedit 来验证这一点。

我怀疑这与 Wow64 重定向有关,但我似乎无法理解我做错了什么?

编辑:为第一个 API 添加了错误检查。

【问题讨论】:

  • 鉴于您尝试获取的密钥在 HKEY_LOCAL_MACHINE 中,您为什么还要使用 RegLoadKey?
  • 因为 HKEY_LOCAL_MACHINE 是他将数据加载到的位置,而不是数据最初位于 ntuser.dat 中的位置。
  • RegLoadKey()的返回值是多少?您没有对其进行错误处理。
  • @RemyLebeau:RegLoadKey 的返回值为 0。正如我所说,为了简洁起见,我将错误处理排除在外。
  • 还有点奇怪的是这个。我将ntuser.dat 文件复制到另一台计算机上,并通过执行 File -> "Load Hive" 使用regedit 打开它,并且它也没有像实际用户帐户上显示的Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\TrayNotify 键。就像那些 Wow64 反射键存储在不同的位置/文件一样?

标签: c++ winapi registry wow64


【解决方案1】:

我想我明白了。对我的原始代码的两个更正:

  1. 首先,从 Vista 开始,我需要为类 hive 加载 Usrclass.dat 文件,而不是 ntuser.dat。这有点道理,因为ntuser.dat 是用户漫游配置文件的一部分,而Classes\Local Settings 不适合图片。所以这里是Usrclass.dat 文件的位置,其中包含非漫游用户数据(主要是 COM 内容,但也有一些其他设置):

    %LocalAppData%\Microsoft\Windows\Usrclass.dat

  2. 用户hive加载后打开的关键是:

    Test123\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify

这是因为原来的HKCU\Software\Classes 被重定向到HKU\<UserSID>_Classes 存储在Usrclass.dat 文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 2011-09-05
    • 2011-12-08
    相关资源
    最近更新 更多