Microsoft Windows Registry Guide, Second Edition

Registry Structure

The structure of the Windows registry is very similar to the structure of the Windows file system. Figure 1-4 compares Registry Editor, the tool you use to edit the registry, and Windows Explorer. (You learn how to use Registry Editor in Chapter 2, “Using Registry Editor.”) In the editor's left pane, which is called the key pane, you see the registry's hierarchy, just as in Windows Explorer you see the file system's hierarchy in the left pane. Each folder in the key pane is a registry key. In the editor's right pane, which is called the value pane, you see a key's values, just as in Windows Explorer's right pane you see a folder's contents.

Take a look at Figure 1-4. In Windows Explorer, you see each of the computer's disks under My Computer. Likewise, in Registry Editor, you see each of the registry's root keys under My Computer. Although you see the full name of each root key in Registry Editor, the standard abbreviations that you see in Table 1-3 are easier to type and read.

Table 1-3 Root Keys

Name

Abbreviation

HKEY_CLASSES_ROOT

HKCR

HKEY_CURRENT_USER

HKCU

HKEY_LOCAL_MACHINE

HKLM

HKEY_USERS

HKU

HKEY_CURRENT_CONFIG

HKCC

Figure 1-4 If you're familiar with Windows Explorer, you probably won't have any trouble understanding the registry's structure, which is similar to that of the file system.

Keys

Keys are so similar to folders that they have the same naming rules. (Registry Editor even uses the same icon for keys that Windows Explorer uses for folders.) You can nest one or more keys within another key as long as the names are unique within each key. A key's name is limited to 512 ANSI or 256 Unicode characters, and you can use any ASCII character in the name other than a backslash (\), asterisk (*), and question mark (?). In addition, Windows reserves all names that begin with a period for its own use.

The similarities between the registry and file system continue with paths. The path C:\Windows\System32\Sol.exe refers to a file called Sol.exe on drive C in a subfolder of \Windows called System32. The path HKCU\Control Panel\Desktop\Wallpaper refers to a value called Wallpaper in the root key HKCU in a subkey of Control Panel called Desktop. This notation is a fully qualified path. I often refer to a key and all its subkeys as a branch.

NOTE

I usually use the term key, but occasionally I use subkey to indicate a parent-child relationship between one key and another. Thus, when you see, for example, text that describes the key Software and its subkey Microsoft, it indicates that Microsoft is a child key under Software.

The last thing to discuss in this section is the concept of linked keys. Windows stores hardware profiles in HKLM\SYSTEM\CurrentControlSet\Hardware Profiles\. Each hardware profile is a subkey nnnn, where nnnn is an incremental number beginning with 0000. The subkey Current is a link to whichever key is the current hardware profile, and root key HKCC is a link to Current. It all sounds terribly convoluted until you see the relationship illustrated in Figure 1-5. To continue the file system analogy, think of links as aliases or shortcuts.

Figure 1-5 When one key is linked to another, as in this example, the same subkeys and values appear in both places.

Values

Each key contains one or more values. In my analogy with Windows Explorer, values are similar to files. A value's name is similar to a file's name. A value's type is similar to a file's extension, which indicates its type. A value's data is similar to the file's actual contents. Click a key in Registry Editor's key pane, and the program shows the key's values in the value pane. In the value pane, you see three columns, which correspond to the three parts of a value:

Every key contains at least one value, and that's the default value. When you look at the registry through Registry Editor, you see the default value as (Default). The default value is almost always a string, but some programs can change it to other types. In most cases, the default value is null, and Registry Editor displays its data as (value not set). When instructions require that you change a key's default value, they usually say so explicitly: “Set the key's default value.”

NOTE

When looking at a key's fully qualified path, you have to figure out whether the path includes a value or not. Usually, the text is clear about whether the path is to a key or includes a value, but sometimes it isn't. For example, does HKCR\txtfile \EditFlags refer to a key or a value? In this case, it refers to a value, and I prefer to use explicit language, such as “the value HKCR\txtfile\EditFlags,” to make the reference clear. Sometimes, paths that don't include a value name end with a backslash (\). If there is no backslash, pay particular attention to the context to make sure you know whether the path is just a key or includes a value. Sometimes a bit of common sense is all you need.

Types

Windows supports the following types of data in the registry. As you look through this list, realize that REG_BINARY, REG_DWORD, and REG_SZ account for the vast majority of all the settings in the registry.

Data in Binary Values

Of all the values in the registry, binary values are the least straightforward. When an application reads a binary value from the registry, deciphering its meaning is up to that program. This means that applications can store data in binary values using their own data structures, and those data structures mean nothing to you or any other program. Also, applications often store REG_DWORD and REG_SZ data in REG_BINARY values, which makes finding and deciphering them difficult, as you learn in Chapter 10, “Finding Registry Settings.” In fact, some programs use REG_DWORD and 4-byte REG_BINARY values interchangeably; thus, keeping in mind that Intel-based computers use little-endian architecture, the binary value 0x01 0x02 0x03 0x04 and the REG_DWORD value 0x04030201 mean exactly the same thing.

Now it gets more complicated. The registry actually stores all values as binary values. The registry API identifies each type of value by a number, which programmers refer to as a constant, and which I tend to think of as the type number. You'll notice this type number mostly when you export keys to REG files—something you learn how to do in Chapter 2. For example, when you export a REG_MULTI_SZ value to a REG file, Registry Editor writes a binary value with the type number 7. Normally, the type number associated with each value type doesn't matter because you refer to the values by their names, but there are times when the information in Table 1-4 will be useful.

Table 1-4 Value Types

Number

Type

0

REG_NONE

1

REG_SZ

2

REG_EXPAND_SZ

3

REG_BINARY

4

REG_DWORD

4

REG_DWORD_LITTLE_ENDIAN

5

REG_DWORD_BIG_ENDIAN

6

REG_LINK

7

REG_MULTI_SZ

8

REG_RESOURCE_LIST

Категории