Home > Articles

Editing with Regedit

  • Print
  • + Share This

Exporting and Importing

Exporting the Registry creates a text file with the .reg extension that you can edit using any text editor. This file contains all the information required to describe the subkeys and values in the subkey you export; in fact, you can import a REG file back into the Registry. When you export a subkey, Regedit writes all of that subkey's descendent subkeys and values. No means is available to export a single subkey without its descendents.

Up to this point, you've used Regedit to work with the Registry. You can also export subkeys to a REG file and edit them using a text editor such as Microsoft Notepad. For example, use the editor's search-and-replace feature to make massive changes to the REG file. Beware, however, because you can inadvertently change values you don't mean to change. More common is editing a REG file to remove subkeys and values that you don't want in the file. If you want to create a REG file that includes a subkey without all its descendent subkeys, for example, edit the file to remove the descendent subkeys. Here's a more practical example: Fergus customized Microsoft Windows 2000 Professional on one computer and then exported the subkey HKCU\Control Panel\desktop to a REG file. Because Fergus is using the REG file to customize other computers and is only interested in a handful of values, he removes the values and subkeys he doesn't want to include in it.

TIP

REG files are indeed a great way to share customizations with other users. After you've edited the file to remove unnecessary subkeys and values, distribute the file. If you want to distribute the file to network users, send it to them as an attachment to a message. Better yet, you can add a command to their logon script that automatically imports the file, put a link to the file on a Web page, or create a network share that contains many REG files from which users can choose. See Chapter 10 for more information.

Aside from editing subkeys and values with a text editor and sharing customizations, exporting subkeys to a REG file has more immediate practical purposes. Export as a backup any subkey in which you're working. When confusion clouds your mind or edits get out of hand, import it back into the Registry to restore the original settings. This will restore values that you change and remove, but it won't remove values that you added to the Registry. Thus, if you added a value that prevents Windows 2000 from working properly, restoring a REG file won't fix the problem; you'll have to remove the new value yourself.

Exporting

Here's how to export all or part of the Registry:

  1. In the key pane, click the subkey at the top of the branch that you want to export to a REG file.

  2. On the Registry menu, click Export Registry File.

  3. You see the Export Registry File dialog box shown in Figure 3.6. This dialog box works like most of the other common dialog boxes.

    Figure 3.6 The Export Registry File dialog box is similar to other common dialog boxes except for the Export Range area.

  4. In File Name, type the name of the file into which you want to export the Registry.

  5. In the Export range area, do one of the following:

    • To export the entire Registry, click All.

    • To export the subkey, click Selected Branch.

Regedit supports two formats for REG files, version 4 and version 5. Earlier versions of Regedit only supported version 4 REG files but Windows 2000's thorough support of Unicode requires the addition of version 5. Version 4 REG files are ANSI text files, whereas version 5 REG files are Unicode text files. When Regedit writes REG_EXPAND_SZ and REG_MULTI_SZ values to version 4 REG files, both of which Regedit encodes as binary in a REG file, it uses ANSI character encoding. When writing the same values to version 5 REG files, it uses Unicode character encoding.

The differences are only significant when you work with different operating systems. Version 5 REG files are only compatible with Windows 2000 and many text editors can't properly edit them. If you must create REG files that are compatible with earlier versions of Windows or your text editor doesn't support Unicode character encoding, create version 4 REG files. Note also that certain values are easier to edit in version 4 REG files. The last caveat, and the most important one for my international readers, is that you must use version 5 REG files if the registry contains multilingual data.

You specify which type of REG file you're creating in the Export Registry File dialog box. In the Save as Type list, click the type of REG file you want to create. Registration Files are version 5 REG files and Win9X/NT4 Registration Files (REGEDIT4) are version 4 REG files. Clicking All Files (*.*) creates version 5 REG files.

NOTE

Make sure that you use clear 8.3 names for REG files. Clear names help you find these files at the MS-DOS command prompt, and 8.3 filenames help make sure that you can easily use the name in command-line options.

Importing

Typical in Windows 2000, you can import a REG file more than one way. The first is the most useful and allows you to import the file without starting Regedit. Click Merge on the file's shortcut menu or, easier yet, double-click the file. If you use this method to import a REG file while Regedit is open, make sure you press F5 to refresh the display so that Regedit reflects changes. The second method uses Regedit:

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

  2. In the Import Registry File dialog box, select the REG file you want to import into the registry.

  3. Click Open.

  4. Regedit displays a message that says Information in filename has been successfully entered into the Registry after importing the REG file.

Import isn't the best name for this feature; merge is better. Regedit merges the REG file's contents into the Registry, replacing existing items and adding new ones. It does not remove subkeys or values that exist in the Registry but not in the REG file; it only adds new items and updates existing ones. Just keep in mind that importing a REG file is not the same as synchronizing a REG file with the Registry. If you must remove a subkey or value from the Registry, remove it using Regedit or write a script that removes it.

Be careful not to accidentally double-click a REG file. Regedit will automatically merge it into the Registry, as Merge is the default command for REG files. To avoid this problem, change the default command for REG files, as described in Chapter 7. You can also save REG files using a file extension other than .reg, preventing accidents. Also consider organizing REG files in their own folder, so that you're more inclined to be careful when working with files in that folder.

CAUTION

Nothing prevents you from importing a Windows 98 or Windows NT 4.0 REG file into Windows 2000, and vice versa. Don't because it might prevent either operating system from working properly. The content of each operating system's registry is sufficiently different for me to jump up and down and wave my arms madly while I give you this warning.

Reading REG Files

REG files look much like classic INI files and are easy to inspect. Open REG files in Notepad by clicking Edit on their shortcut menus. The first line of a version 5 REG file always contains Windows Registry Editor version 5.00, which identifies the file as a REG file. Version 5 REG files start with REGEDIT4. Following a single blank line, the remainder of the file contains the keys and values Regedit exported.

Listing 3.2 shows a REG file. It contains multiple sections. Each subkey is in its own section. The fully qualified name of each subkey is between square brackets. Each subkey's values are in the subkey's section. Except for default values, values' names are in quotation marks. Regedit represents in REG files default values using a single at sign (@). Values' data look different depending on their types (see Table 3.3). Anatomy lesson over.

Listing 3.2  A Sample REG File

Windows Registry Editor version 5.00


[HKEY_CURRENT_USER\Control Panel\Desktop]
"DragFullWindows"="1"
"FontSmoothing"="1"
"wallpaper"=""
"TileWallpaper"="0"
"UserPreferencemask"=hex:a0,00,00,00
"WallpaperStyle"="0"
"ScreenSaveLowPowerActive"="1"
"ScreenSavePowerOffActive"="0"
"ScreenSaveActive"="0"
"ScreenSaveTimeOut"="60"
"ScreenSaveUsePassword"=dword:00000000
"SmoothScroll"=hex:01,00,00,00
"WheelScrollLines"="3"
"Pattern"=""
"DragWidth"="2"
"DragHeight"="2"
"DoubleClickWidth"="4"
"DoubleClickHeight"="4"
"HungAppTimeout"="inget"
"WaitToKillAppTimeout"="inget"
"CoolSwitchRows"="inget"
"CoolSwitchColumns"="inget"
"MenuShowDelay"="400"
"test"=dword:00000054

[HKEY_CURRENT_USER\Control Panel\Desktop\ResourceLocale]
@="00000409"

[HKEY_CURRENT_USER\Control Panel\Desktop\WindowsMetrics]
"MinAnimate"="1"

Table 3.3  Format of Values in REG Files

Data Type

Version 4

Version 5

REG_BINARY

hex:00,00,00,01

hex:00,00,00,01

REG_DWORD

dword:00000001

dword:00000001

REG_EXPAND_SZ

hex(2):48,49,00

hex(2):48,00,49,00,00

REG_MULTI_SZ

hex(7):4C,69,6E,65,20,

hex(7):4C,00,69,00,

31,00,4C,69,6E,65,20,

6E,00,65,00,20,00,31,

 

32,00,00

00,00,00,4C,00,69,00,

 

 

6E,00,65,00,20,00,32,

 

 

00,00,00,00,00

 

REG_SZ

"A string"

"A string"


Protecting Yourself

I can't stress enough the importance of protecting yourself while editing the Registry. You can restore a backup copy of the Registry, but less-drastic solutions are more feasible. Create a backup copy of a value before changing it, for example, by creating a backup value and naming it whatever you like. Then copy the original value to the Clipboard and paste it to the backup value. You'll always know what data you replaced in the value.

If you're working with a number of values within a subkey, export the subkey to a REG file before editing it. If things go wrong, import the file to restore the subkey's settings. You can replace the mangled subkey by removing it before importing the REG file.

A sorted combination of Regedit and Regedt32 is often the best solution. Regedit is the easiest of the sibling Registry editors to use, but Regedt32 has more powerful features for backing up subkeys. Use Regedt32 to save subkeys as hive files and use Regedit to edit the Registry. Flipping back and forth between both programs might seem silly, but you get used to the idea quickly. Just make sure you refresh either program's window if you make changes to the registry using the other.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.