Reputation: 51
I am trying to write some C/C++ code that will import a .reg file into the registry. The MSDN has functions for importing a file for specific keys but I want to import for example the entire HKCU hive.
Upvotes: 0
Views: 893
Reputation: 596387
There is no Win32 API for importing a .reg
file into the Registry 1. You will have to parse the file yourself and translate the instructions into appropriate Registry API function calls as needed - Reg(Open|Create)KeyEx()
, RegSetValueEx()
, RegDelete(Key|Value)()
, etc.
1: don't be confused by the existence of RegLoadKey()
, RegReplaceKey()
, and RegRestoreKey()
. They are intended for loading files created by RegSaveKey/Ex()
, which are not text-based .reg
files.
Otherwise, you can just use ShellExecute/Ex()
or CreateProcess()
to execute regedit.exe /s <filename>
or reg.exe import <filename>
with the path to the .reg
file as a command-line parameter, letting regedit
/reg
handle the import for you. This would be the easiest way to go.
Upvotes: 3