Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backing up registry using batch

I have windows 7 ultimate 32 bit and and I need a batch script that can backup the registry to a .reg file call "Registry backup" in the same directory as the batch file can any one help me find a code to do this.

like image 674
09stephenb Avatar asked Mar 22 '23 06:03

09stephenb


2 Answers

Exporting the whole registry to a single .reg file is not so easy, but you can use the Reg.exe utility that is installed with Windows to export a chosen root key.

Documentation for Reg.exe can be found here.

For example, to save each of the valid root keys (and all sub-keys) to their own files, you could do this:

ECHO OFF
reg export HKLM hklm.reg > nul
reg export HKCU hkcu.reg > nul
reg export HKCR hkcr.reg > nul
reg export HKU  hku.reg > nul
reg export HKCC hkcc.reg > nul

There is also a save option, that does a similar thing but stores the data in a different format.

like image 188
Roger Rowland Avatar answered Apr 01 '23 23:04

Roger Rowland


To simplify Mr. Roger Rowland's answer, we may execute this syntax within CMD.

C:\Users\MrCMD>FOR %K IN (LM CU CR U CC) DO @REG.EXE EXPORT HK%K hk%K.reg [enter]

Or do those more informative within Batch Script, we may named it "BUpRegWin.CMD"

@echo off
setlocal
for %%k in (lm cu cr u cc) do call :ExpReg %%k
goto :eof
:ExpReg
reg.exe export hk%1 hk%1.reg > nul
if "%errorlevel%"=="1" (
  echo ^>^> Export --hk%1-- Failed.
) else (
  echo ^>^> Export --hk%1-- Fine.
)
goto :eof
endlocal

Brighter ideas are welcome. Feel free to improve. Thank you in advanced. :) :) :)

like image 32
Rhak Kahr Avatar answered Apr 01 '23 23:04

Rhak Kahr