LilMoke
LilMoke

Reputation: 3444

Registry hive question

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

Upvotes: 0

Views: 1737

Answers (3)

Luke
Luke

Reputation:

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.

Upvotes: 3

Basilevs
Basilevs

Reputation: 23896

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.

Upvotes: 0

Callie J
Callie J

Reputation: 31296

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 :-)

Upvotes: -1

Related Questions