Saving and Restoring Keys

You can use Regedt32 or Regedit to save all or part of a Registry subtree to a file. This file can then be used to restore that Registry or the Registry of another computer by replacing a damaged key with the contents of the file. If you save the key to a file by using Regedt32, you can also load the file into Regedt32 on any computer to examine its contents or to edit it.

Regedt32 and Regedit save Registry keys in different formats and use different methods for restoring the Registry. Decide which tool you will use before beginning the process. You cannot save a key to a file with one tool and use the other tool to restore a Registry with that file.

The remainder of this section describes how to save and restore Registry keys by using Regedt32 and Regedit.

Using Regedt32 to Save and Restore Registry Keys

To save a Registry key and its subkeys to a hive file, use the Save Key command in Regedt32. You can then use the Load Hive command in Regedt32 to view and edit the file and use the Restore command to replace a Registry key with the file contents.

Note

Do not confuse the hive files you create by using the Save Key command with the hive files created by the system for its own use. The system hive file of a remote computer, usually stored in Systemroot\System32\Config and Systemroot\Profiles, can be loaded or restored only while Windows NT is not running on that computer.

Changes in the Registry are saved automatically, whether you make changes by using a Registry editor or by changing settings in applications. The Save Key command is used specifically to save portions of the Registry as a file on disk.

To use the Save Key command, you need Backup permissions, which you have if you are logged on as a member of the Administrators group.

You can use the Save Key command on any key. However, you cannot save volatile keys. A volatile key is one that is created when the system starts and deleted when it stops. Some volatile keys have nonvolatile subkeys that can be saved. For example, the HKEY_LOCAL_MACHINE\Hardware key is volatile, but you can save the nonvolatile subkeys under that key. To view the entire Hardware key for debugging, save it in a text file by using the Save Subtree As command on the Registry menu, as described later in this chapter.

To save a Registry key by using Regedt32

1. Select the key that you want to save as a hive file on a disk.

2. From the Registry menu, click Save Key, then type a filename for the saved file in the Save Key dialog box.

Note

When saving a hive file on a remote computer, use a path relative to the remote computer, not to the local computer. For example, if you are using your G: drive to connect to \\Text01\Public to save Hive.tst, enter \\Text01\Public\Hive.tst, not G:\Hive.tst. The G:\Hive.tst entry directs Regedt32 to save the file on the G: drive of the remote computer, not the G: drive of the local computer.

The selected key is now saved as a file. When you use the Load Hive command, you can select the filename for any files that you saved by using the Save Key command.

For example, as part of system maintenance, you use the Save Key command to save a key as a file. When the key that you saved is ready to be returned to the system, you use the Restore command.

You can use the Restore command to make a hive file a part of the system configuration by loading the data from the hive file into an existing key. The contents of the file overwrite and replace the contents of the Registry key, except for the key name.

To use the Restore command, you need Restore permissions, which you have if you are logged on as a member of the Administrators group.

To restore a key by using Regedt32

1. Select the key you want to restore from a hive file.

2. From the Registry menu, click Restore, then enter the name of the hive file from which data will be taken to overwrite the key.

Note

When restoring a hive from a file on a remote computer, use a path relative to the remote computer, not to the local computer.

You cannot restore a key while the system is using it or any of its subkeys. For example, you cannot restore the SAM or Security keys because the system is always using these keys. The Restore command is used only for special conditions, such as to restore user profiles on a damaged system. To switch to a backup version of a hive, use Regrest.exe, a tool distributed on the Windows NT Workstation Resource Kit CD. For more information about Regrest, see Rktools.hlp, a Help file for tools on the Windows NT Workstation Resource Kit CD.

Using Regedit to Save Registry Keys

You can save Registry keys and their subkeys by using the Export Registry command in Regedit. This command saves a specific branch or the entire Registry in a text file with a .reg filename extension. Later, you can use the Import Registry command to rebuild a key or the entire Registry from an exported Registry file.

You can run Regedit from the Regedit window within Windows NT or from a command prompt. This section describes both methods.

To save a Registry key by using the Regedit window

1. From the Registry menu, click Export Registry File.

2. In the Export Range box of the Export Registry File dialog box, specify the part of the Registry you want to save.

– Or –

The Selected Branch edit box displays the name of the Registry keys or subkeys that were selected when you clicked the command. You can save that key or type the name of any key over it. (Regedit saves the key you select and all of the subkeys and value entries it contains.)

3. Type a path and filename for the Registry file in the File name edit box, or navigate to a folder by using the Windows NT Explorer interface in the Export Registry File dialog box, then type a filename.

Regedit appends the .reg filename extension to the filename you enter.

4. Click Save to return to Regedit.

To save a Registry key by using Regedit from a command prompt.

· Run Regedit from a command prompt to export Registry keys to .reg files. Use the following format:

regedit /e Filename.reg [Registry key]

The Registry key field is optional. The default is to export the entire Registry to a file.

Using Regedit to Restore Registry Keys

You can restore or replace a Registry key by importing a .reg file containing that key into the Registry. The contents of the Registry key are overwritten and replaced by the contents of the .reg file. If the Registry that is being restored is running on a computer that can still run Windows NT, use the Regedit window to restore the key. However, you can also run Regedit from the command prompt, if necessary.

This section describes the Regedit window interface method first, then the command prompt method.

Warning Use extreme caution in restoring keys. As with any Registry changes, an error can prevent Windows NT from loading and running, or prevent users from logging on to the system.

To restore a Registry key by using the Regedit window

1. From the Registry menu, click Import Registry File.

2. Locate the .reg file you are using to restore the Registry key, then click OK.

To restore a Registry key by using Regedit from a command prompt

· If the Registry is damaged or if the system no longer starts, run Regedit from a command prompt to diagnose and correct the problem. From the command line, use Regedit commands to export, import, or create a Registry.

You can also import Registry keys to .reg files from a command prompt. Use the following format:

regedit /i filename.reg

– Or –

regedit /c filename.reg

The /i (import) switch is used to import .reg files that contain a part of the Registry. The Registry keys (and their contents) saved in the .reg file overwrite only the analogous keys in the Registry. Please note that this command does not have a field to specify a Registry key. All of the Registry keys (and their subkeys and values) saved in the .reg file overwrite the analogous keys in the Registry. You cannot specify that only a subset of the keys be replaced.

The /c (complete) switch assumes that the .reg file contains a copy of an entire Registry. The contents of the .reg file overwrite all keys in the Registry.

Caution Use the regedit /c command with extreme care, and only when you are sure that the .reg file specified contains a complete image of the Registry. The regedit /c command replaces the entire contents of the Registry.