The registry is a centralized, hierarchical database
for application and system configuration information. Access to the
registry is through registry keys,
which are analogous to file system directories. A key can contain other
keys or key/value pairs, where the key/value pairs are analogous to
directory names and file names. Each value under a key has a name, and
for each key/value pair, corresponding data can be accessed and
modified.
The user or administrator can view and edit the registry contents through the registry editor, using the REGEDIT command. Alternatively, programs can manage the registry through the registry API functions described in this section.
Note
Registry programming is
discussed here due to its similarity to file processing and its
importance in some, but not all, applications. The example will be a
straightforward modification of the lsW example.
The registry contains information such as the following and is stored hierarchically in key/value pairs.
Windows
version number, build number, and registered user. However, programs
usually access this information through the Windows API (the version program, available in the Examples).
Similar information for every properly installed application.
Information about the computer’s processor type, number of processors, memory, and so on.
User-specific information, such as the home directory and application preferences.
Security information such as user account names.
Installed services .
Mappings
from file name extensions to executable programs. These mappings are
used by the user interface shell when the user clicks on a file icon.
For example, the .doc and .docx extensions might be mapped to Microsoft Word.
UNIX systems store similar information in the /etc
directory and files in the user’s home directory. The registry
centralizes all this information in a uniform way.
Figure 1 shows a typical view from the registry editor and gives an idea of the registry structure and contents.
The
specific information regarding the host machine’s processor is on the
right side. The bottom of the left side shows that numerous keys contain
information about the software applications on the host computer.
Notice that every key must have a default value, which is listed before
any of the other key/value pairs.
Registry Keys
Figure 3-1
shows the analogy between file system directories and registry keys.
Each key can contain other keys or a sequence of values associated with a
key. Whereas a file system is accessed through pathnames, the registry
is accessed through keys and value names. Several predefined keys serve
as entry points into the registry.
HKEY_LOCAL_MACHINE
stores physical information about the machine, along with information
about installed software. Installed software information is generally
created in subkeys of the form SOFTWARE\CompanyName\ProductName\Version.
HKEY_USERS defines user configuration information.
HKEY_CURRENT_CONFIG contains current settings, such as display resolution and fonts.
HKEY_CLASSES_ROOT
contains subordinate entries to define mappings from file extensions to
classes and to applications used by the shell to access objects with
the specified extension. All the keys necessary for Microsoft’s
Component Object Model (COM) are also subordinate to this key.
HKEY_CURRENT_USER
contains user-specific information, including environment variables,
printers, and application preferences that apply to the current user.