Using Command-Line Options
Regedit provides command-line options you can use to export and import REG files. To use them, click Run on the Start menu, and then type regedit followed by any of the options you want to use. These command-line options are also suitable to use at the MS-DOS command prompt or within batch files. If you have a command that you want to use often, create a shortcut for it.
Regedit is the only Registry editor in Windows 98. In Windows 98, it has more command-line options than it does in Windows 2000. Users specify the location of the per-computer and per-user hive files (System.dat and User.dat) using the /L and /R options. In Windows 2000, Regedit doesn't support these options. The result is that Regedit always operates on the hive files that are loaded into the Registry. If you want to use Regedit's command line to export a hive file that's not already loaded into the Registry, you must first load that hive file using Regedt32, which you learn about in Chapter 4. An alternative is to use Microsoft Registry Console Tool, an MS-DOSbased program with features similar to Regedt32 that you learn about in Chapter 10.
The following gives you a brief summary of Regedit's command-line options, which the following sections describe in more detail:
REGEDIT [/S] filename REGEDIT /E filename [subkey]
Use the /E command-line option to export a subkey. Omit subkey, and Regedit exports the entire Registry. Regedit creates version 5 REG files, which are only compatible with Windows 2000. Note that subkey must be a fully qualified name, and it must begin with the root key's full name, not its abbreviation. For example, the following command exports HKCU\ Control Panel\desktop:
regedit /E Docfiles.reg "hkey_classes_root\docfile"
A practical use for the /E command-line option is to back up the Registry. Create a shortcut that executes this command: regedit /E backup.reg. Just remember that it backs up the current Registry, including the current user's hive file, Ntuser.dat, but not other users' hive files. You must load those hive files using Regedt32 before trying to export them using Regedit.
Importing REG Files
To import a REG file, specify its filename without any other command-line options: regedit filename. Regedit imports the REG file the same way it does if you were to click Import Registry File from the Registry command.
When you import a REG file, Regedit confirms whether you really want to merge the file into the Registry. The messages says Are you sure you want to add the information in filename to the registry? Click Yes to complete the operation. This is an improvement over earlier versions of Regedit, which promoted accidents by blindly importing any REG files on which users accidentally double-clicked. After it finishes merging the file, Regedit displays a message that says Information in filename has been successfully entered into the registry.
You can suppress both of these messages using the /S command-line option. This option, which must be the first option on the command line, instructs Regedit to import the Registry file without confirming the operation and without reporting when it's finished. Although you do want to be careful with this option, you can use it in batch files so that Regedit quietly imports files without causing the batch file to pause while users close annoying dialog boxes. Great for logon scripts, it is.
Regedit cannot overwrite subkeys and values that are in use by Windows 2000 or another program. When in use, the operating system locks them. When Regedit tries merging a REG file into a subkey or value that's locked, you see a message that says Cannot import filename: Not all data was successfully written to the registry. Some keys are open by the system or other processes.