简体   繁体   中英

Import registry file to registry using windows API

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM