Section 13.2. Adding and Deleting Registry Keys and Values

The Registry Editor, as mentioned earlier, is the primary tool for viewing, modifying, and deleting data in the Registry. And as you'll see later in this chapter, it also allows you to conveniently import and export data (via Registry patches), which you can think of as another form of data entry.

Basic data entry in the Registry Editor is fairly simple. In order to type data, you must first create a value to hold it. Depending on your goal, you may also need to create a new key in which to place the value.

To create a new key or value, use Edit New. The key or value then appears within the currently selected key, with the name New Key or New Value #1, respectively. A new string value will have the null string as its value; a new binary value will show the following message in parentheses: "(zero length binary value)." A new DWORD value will show up as zero: 0x00000000 (0). You can then edit that value (see later in this chapter) to change it. New keys aren't created empty, either. They all contain the (Default) value described in the preceding section.

To delete a key or value, select it and click Edit Delete, or simply press the Delete key. But be warned, there's no undelete, so you might want to first write out the branch containing the key you're about to delete as a .reg file (see "Backing Up the Registry" and "Exporting and Importing Registry Data with Patches," later in this chapter). Or, you can use Edit Rename to rename the value or key. Because applications access values and keys by their names, renaming has the effect of disabling or "hiding" the item from the application that uses it, while preserving its data.

To edit a value, double-click on its icon or name, or highlight it and use Edit Modify. You will see an edit box appropriate to the value type. When editing a string value, the Registry Editor provides a standard text box, in which you can type text as well as copy and paste (by right-clicking on the text, or by using Ctrl-C, Ctrl-X, and Ctrl-V). Binary values have a more complicated and less familiar edit dialog, which allows data entry via hex codes on the left, or plain text on the right. Finally, DWORD values have a simpler edit interface, providing only for entry of a single number (in either hex or decimal format). Cut, Copy, and Paste work in DWORD and Binary dialogs as well. See the preceding section, "What's in the Registry," for more details on the different types of values.

Unfortunately, automation in the Registry Editor is virtually nonexistent. For example, you can't copy and paste whole keys or values like you might expect (given the familiar Explorer-like interface), but you can copy key and value names to the Clipboard by pretending you're going to rename them, and then pressing Ctrl-C to copy. Another useful tool is the Copy Key Name command on the Edit menu, which copies the full path to the selected key to the Clipboard (very handy for writing this book, for example). It doesn't copy the contents of the key, nor does it include the selected value, however.

If you want to duplicate an existing value, double-click it and select all of the data in the Edit window (see Figure 13-4).

Figure 13-4. Copying an existing Registry value

Ctrl-C will copy the data to the Clipboard. Then create a new value, being sure to match the type (string, binary, or DWORD) of the original value. Type the desired value name, double-click the new value to edit it, and then use Ctrl-V to paste the copied data into the edit window.

Duplicating values can be handy not only when using an existing value as a template for a new value, but also whenever you're going to make changes to an existing value. You can make little "inline backups" by creating a new value (whatever.bak, for instance) and pasting in the old value data before you change it. This might seem a little tedious, but it can prevent future headaches if you're about to change a complex value whose format you aren't completely sure you understand, or even if you anticipate having to roll back a value to its previous state for some reason.

Unfortunately, there's no easy way to copy a key and all of its contents in the Registry Editor. If you want to copy an entire key and all its values, you'll have to do it one value at a time. It's usually much easier to export the key, edit the resulting file with a text editor, and then import the edited file. (See "Exporting and Importing Registry Data with Patches," later in this chapter.)

In addition to the Edit menu, you may find the Registry Editor's context menus convenient. Right-clicking on a key in the left pane gives a context menu with Expand or Collapse, New, Find, Delete, Rename, and Copy Key Name. (Expand displays a key's subkeys. It will be grayed out if there are no subkeys to display, and it will be replaced with Collapse if said subkeys are already showing.) Right-clicking with a value selected in the right pane gives a context menu with Modify, Delete, and Rename. Right-clicking in the right pane with no value selected gives a context menu with New (to create a new value). Press Shift-F10 to open a context menu without having to use the mouse.

Part II: Nutshell Reference