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 filename 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 pretty 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 both as a backup in case things go wrong and as a change log to help you determine what was modified after the change.



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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