我需要从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");
}
问题是SoftwareClassesLocal SettingsSoftwareMicrosoftWindowsCurrentVersionTrayNotify
密钥未加载,即使我知道它存在于实际用户配置文件中。我可以通过加载用户帐户和使用64位regedit来验证这一点。
我怀疑这与WOW64重定向有关,但我似乎不明白我在做什么错?
编辑:添加的错误检查第一个API。
我想知道了。我原始代码的两个更正:
-
首先,因为Vista我需要为hive而不是
ntuser.dat
加载Usrclass.dat
文件。这有意义,因为ntuser.dat
是用户漫游配置文件的一部分,并且ClassesLocal Settings
不适合图片。因此,这是Usrclass.dat
文件的位置,其中包含非漫游用户数据(主要是com的东西,但也是其他一些设置):%localappdata% Microsoft Windows usrclass.dat
-
用户Hive负载后打开的关键是:
test123 本地设置 Software Microsoft Windows Currentversion TrayNotify
这是因为原始HKCUSoftwareClasses
被重定向到Usrclass.dat
中存储的HKU<UserSID>_Classes
。