Backing up registry using batch

南笙酒味 提交于 2019-12-06 04:42:13

问题


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.


回答1:


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.




回答2:


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. :) :) :)



来源:https://stackoverflow.com/questions/20655673/backing-up-registry-using-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!