无法在32位服务中使用RegLoadKey加载64位密钥

时间:2012-12-19 06:07:31

标签: c++ winapi registry wow64

我需要从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的错误检查。

1 个答案:

答案 0 :(得分:2)

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

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

    %LOCALAPPDATA%\微软\的Windows \ Usrclass.dat

  2. 用户配置单元加载后打开的键是:

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

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

相关问题