Hello,
Does anyone have a smal example of how to programmatically, in c/c++, load a users registry hive? I would loike to load a hive set some values and close the hive.
Thanks in advance for any help.
Tony
Hello,
Does anyone have a smal example of how to programmatically, in c/c++, load a users registry hive? I would loike to load a hive set some values and close the hive.
Thanks in advance for any help.
Tony
I haven't got a specific example, but the Windows API calls you need would be:
RegOpenKeyEx()
to load the registry
key RegSetValueEx()
/ RegGetValue()
[and sister
functions] to get/set registry valuesRegCloseKey()
to close the
registry.There's some example code behind this link on codersource.net ... although I can't vouch for how complete or correct it is. Review against the MSDN :-)
Documentation says you should pass predefined key HKEY_CURRENT_USER as first argument of RegOpenKeyEx function. You can also enumerate HKEY_CURRENT_USER passing it directly to RegQueryInfoKey.
You can use RegLoadKey() and RegUnLoadKey(). You can build the paths to the user hives (NTUSER.DAT) via the HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList. However, it's generally not a good idea to use these functions willy-nilly. If the user tries to logon while you have his profile loaded, he will be unable to load his profile and will get a temporary default profile.