Kevin is a Software Developer with 20 years experience designing and building business intelligence and system integration solutions.
Backing up the Windows Registry is an accepted best practice before making changes to the Windows Registry. This is quite easy using the RegEdit tool in Microsoft Windows. You can export the whole registry or just one branch. This tutorial will show you how using the command line method and also using VBScript. This is handy in an enterprise environment where you can't go from computer to computer.
Export (Backup) the Whole Registry (Command Line)
The Command Line method provides several options to be used in order to interface with the registry. For exporting a branch or the whole Registry, you can one of the following commands
The /e option notifies the regedit tool that is has to export the contents of the registry with or without a branch as follows:
regedit /e c:\reg_backup.reg
This command exports the complete registry to the reg_backup.reg file on the c drive. Note that the file does not have to be a reg file. Regedit can export to Word or a text file or a file of another type like rich text (rtf) also. See the screenshot below.
regedit /L:c:\system.dat /R:c:\user.dat /e c:\backup.reg
This command is similar to the first except that it is using the system.dat and user.dat files which are the registry repositories.
regedit /e c:\backup.reg HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
This command would export on the specified branch and key. However, I strongly urge anyone modifying the registry to take a full backup because messing up the registry would have dire consequences on the computer's functionality, even preventing Windows from starting.
Export Registry Using VBscript
Another way to export the contents of the Registry is to use VBScript or JScript. The principal is the same. If you are exporting a key, then you would need to assign it to a variable as in the example below. Next assign a backup file to another variable like regFile. If you want to store the backups in a folder locally or on the network, make sure the location exists or check to see if it exists beforehand and create folder is needed. To get a handle on the file using VBScript, you will to create a FileSystem Object, like fso, in the provided example. Then check if the file exists assign the regedit command with the /E option and the backup file without a key or with a key. Both examples are provided below. Use the one that best fits your needs. Finally execute the command passing in the regCmd variable.
VB Script Code
This article is accurate and true to the best of the author’s knowledge. Content is for informational or entertainment purposes only and does not substitute for personal counsel or professional advice in business, financial, legal, or technical matters.
© 2012 Kevin Languedoc
Kevin Languedoc (author) from Canada on May 13, 2013:
The reg key the same in xp. Also check to see if you need to double quote for empty spaces
regCmd = "regedit.exe /E """ & backup.reg & """"
Marc on April 30, 2013:
This is working in Win7, but not in XP, any idea what's wrong?