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