Sunday, 13 May 2012

Simple export of registry subkeys in HKCU\Software and HKLM\Software

I didn't write .cmd scripts for a very long time. But few weeks ago I faced random failures on my old laptop, so I was forced to migrate. Since the old one was intensively used for a year, a lot off unnecessary stuff was gathered. Smooth migration was rather impossible, so it was decided to reinstall system from scratch and install only the needed software.

I don't like different automatic migration software, so all applications were reinstalled and most of them were configured manually again. But some applications had to keep their old configuration, and this configuration was generally located in registry by the keys like HKLM\Software\<Application> and HKCU\Software\<Application>.

I found it very annoying to parse the list of subkeys (more than 100 applications were installed) looking for the ones I need, so I decided just to dump all "Software" keys to backup and restore just the needed pieces when needed. But if I dump "Software" to a single file, it will be the same issue to extract the needed pieces after.

To solve this problem I used a script that I wrote about 10 years ago, but it is actual even now. It is VERY simple, and I spent much more time to write this post than these two lines:

for /f "tokens=3 delims=\" %%i in ('reg query HKLM\Software') do reg export "HKLM\Software\%%i" "%%i_HKLM.reg" /y
for /f "tokens=3 delims=\" %%i in ('reg query HKCU\Software') do reg export "HKCU\Software\%%i" "%%i_HKCU.reg" /y

Thats it. Put those lines to some .cmd file, execute it, and you will have a bunch of .reg files per Software subkey both HKLM and HKCU.

No comments:

Post a comment