Recipe9.4.Exporting Registry Files


Recipe 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 import its contents into the registry.

The format for this file is easy to follow. Here is an example registry file containing the contents of the HKLM\Software\Google key:

Windows Registry Editor Version 5.00     [HKEY_LOCAL_MACHINE\Software\Google] "DesktopBarAdminInstall"=dword:00000001     [HKEY_LOCAL_MACHINE\Software\Google\CustomSearch]     [HKEY_LOCAL_MACHINE\Software\Google\Deskbar] "path"="C:\\PROGRA~1\\Google\\GGTASK~1.DLL" "Version"=dword:00000051     [HKEY_LOCAL_MACHINE\Software\Google\Miniviewer] "path"="C:\\Program Files\\Google\\ggviewer81-47.exe" "Version"=dword:00000051     [HKEY_LOCAL_MACHINE\Software\Google\NavClient] "test"="41" "brand"="GGLD" "installtime"="1068347808" "sent"=dword:00000001     [HKEY_LOCAL_MACHINE\Software\Google\NavClient\Obsolete]     [HKEY_LOCAL_MACHINE\Software\Google\Verscheck] "path"="C:\\Program Files\\Google\\ggverscheck81-47.exe" "Version"=dword:00000051

Exporting the registry is useful if you need to implement a significant change to a system. A registry export can act as both a backup in case things go wrong and a change log to help you determine what was modified after the change.



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net