9.4. Exporting Registry Files

Problem

You want to export part of the registry to a registry (.reg) file.

Solution

Using a graphical user interface

  1. Open the Registry Editor (regedit.exe).

  2. In the left pane, browse to the key you want to export.

  3. Right-click on the key and select Export.

  4. Enter a file name to save the export to and click Save.

Using a command-line interface

The following command exports part of the registry to a file:

> regedit /e <FilePath> 
                  <RegKey>

For example:

> regedit /e c:\rallencorp.reg HKEY_LOCAL_MACHINE\Software\Rallencorp

Using VBScript

' This code exports the contents of a key to a registry file.
' Since there are no scripting functions to do this, I simply
' shell out to the regedit tool to do it.
   
' strCommand = "regedit /e <FilePath> 
                  <RegKey>"
strCommand = "regedit /e c:\rallencorp.reg HKEY_LOCAL_MACHINE\Software\Rallencorp"
set objWshShell = WScript.CreateObject("WScript.Shell")
intRC = objWshShell.Run(strCommand, 0, TRUE)
if intRC <> 0 then
   WScript.Echo "Error returned from exporting registry: " & intRC
else
   WScript.Echo "No errors returned from exporting the registry file"
end if

Discussion

The Registry Editor allows you to export parts of the registry to a text-based file. You can then modify the file and import it back into the registry (perhaps on another host) using Registry Editor (see Recipe 9.5). These registry files have an extension of .reg. Windows recognizes this extension so that if you double-click on a .reg file, you will automatically be prompted to ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.