tags:

views:

384

answers:

3

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

A: 

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 values
  • RegCloseKey() 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 :-)

Chris J
I know of those functions and have used them many times before, but how do I load a users hive? Maybe I am missing something with those functions, so I will look again. I do not remember anything about loading a specific hive for a user.
Tony
A: 

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.

Basilevs
+1  A: 

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.