How to insert a line into a .reg file with a batch command?

January 19, 2012 at 19:34:26
Specs: Windows 7
I have a batch file that exports a registry key to a text (.reg) file. What I want to do is then open the reg file, and insert a line to delete a key first, right after the "Windows Registry Editor Version 5.00" line, so that it ends up looking something like this:

****

Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Software\mykey] <--- this is the line that gets inserted

[HKEY_CURRENT_USER\Software\mykey\data]
"alias.somedata.16.20790.aliasname"="blah"
"alias.more.16.20790.aliasname"="blah2"
etc.

****

What do I need to add to my batch file to insert this line?


See More: How to insert a line into a .reg file with a batch command?

Report •


#1
January 20, 2012 at 08:27:12
you could do it this way:

echo Windows Registry Editor Version 5.00 > newregfile.reg
echo. >> newregfile.reg
echo [HKEY_CURRENT_USER\Software\mykey] >> newregfile.reg
for /f "skip=2" %%a in (oldregfile.reg) do echo %%a >> newregfile.reg


note that i took out the - in [-HKEY... looked like a typo


Report •

#2
January 20, 2012 at 11:40:10
Thanks. I actually ended up doing something very similar with the "skip" option.

The hyphen is NOT a typo. It is there to tell regedit to delete the entire key before the remaining lines (without a hyphen) are merged back into the registry.


Report •
Related Solutions


Ask Question