2.2 What Goes in the RegistryNo two snowflakes are alike. It's not quite true to say that no two Registries are alike, but they can vary significantly from machine to machine. There's a standard set of keys Windows 2000 uses, but even this standard set varies somewhat, depending on whether the computer's running Windows 2000 Professional or a member of the Windows 2000 Server family, what optional components are installed, and how the machine's network connection is configured. The Registry help files included with the Windows 2000 Resource Kit (as well as the material in Chapter 11 ) explain what individual keys are for, but using that data to grasp what's important is like trying to build a watch out of a bag full of parts; it's much more instructive to examine a working watch and see how its parts relate. To provide a working watch for your entertainment, this section examines the most important subkeys of the root keys described earlier in this chapter. 2.2.1 Major Subkeys of HKLMHKLM 's purpose is to store all the important configuration data for the local machine. It doesn't contain any information about other machines on the network or about user-specific configuration data; instead, it's nothing but settings for the machine where it's stored. HKLM has four important subkeys. 2.2.1.1 HARDWAREAll the keys and subkeys of HKLM\HARDWARE are generated by Windows 2000 at boot time and exist only in memory; they aren't stored on disk. This may seem odd, but when you consider the Windows 2000 boot process, it makes more sense. The boot loader (NTLDR.COM ) is loaded by the standard DOS boot mechanism. When it executes, it loads and starts the Windows 2000 kernel. The kernel in turn must first start up the hardware abstraction layer; the HAL provides a buffer between the gory details of hardware resources and the neatly structured system of device drivers the operating system uses to talk to hardware. For this approach to work, the HAL must register the hardware it finds, but at the time it finds those devices, it may not have found any disks to register the data on! Keeping the hardware keys in memory nicely solves this problem. There are four subkeys of HKLM\HARDWARE. For the most part, your interaction with them will be very limited, especially since you can't change them. All the information you might gain by manually inspecting these subkeys is more easily available through the System Properties dialog box. Having said that, though, here they are:
2.2.1.2 SECURITYThe SECURITY subkey holds two important collections of data. First off, it caches the local copy of the Security Account Manager database in HKLM\SECURITY\ SAM. This database is the foundation of all the system's access controls. Besides ACLs for every object that has permissions assigned to it, this subkey contains a roster of local or domain accounts and groups, since the ACLs grant permissions to groups and users. This subkey actually maps to a separate hive, and its data is normally readable only by kernel services that have the appropriate "need to know." The SAM data has been kept here since Windows NT 3.1 first shipped, although in Windows 2000 it's kept here only for backward compatibility and to support machines that aren't part of an Active Directory domain. As you learned in User Profiles Demystified, NT 4.0 adds the capability to use user and group policies. These policies also live in subkeys of HKLM\SECURITY. These policies control what users can and can't do on the machine, ranging from small things like changing the desktop wallpaper to big things like rebooting servers or editing the Registry. The data in the SAM is encrypted, so you can't directly access or modify it. Instead, you need to use the System Policy Editor (as described in Chapter 6) to set profiles, which NT then loads automatically into this subkey when they're needed. Not even the Administratoraccount has permission to open these subkeys. Even if you change the ownership rights on SECURITY or its hive so that your account can open it, you'll find that the data there is encrypted. Even if you manage to decrypt it, the data is in an undocumented format that probably won't do you any good. Don't despair, though: there are functions in the Win32 API you can use to create, read, and change security descriptors, permissions, and policies.
2.2.1.3 SOFTWAREApplications and system components store their settings under subkeys of SOFTWARE. By convention, programs that keep things here are supposed to create subkeys using the program and/or vendor name, then put their settings underneath. HKLM\SOFTWARE\TechSmith\Snagit32 thus contains settings for TechSmith's SnagIt/32 screen-capture utility. Most of the operating-system components keep their systemwide settings under HKLM\SOFTWARE\ Microsoft\ComponentName. Settings that belong only to a single user are stored elsewhere. The exact contents of this subkey vary from machine to machine, depending on what software's installed. My best estimate is that about 80% of the time you spend viewing or editing the Registry will be spent in various subkeys of HKLM\SOFTWARE. In particular, HKLM\Software\Microsoft\Windows NT holds most of the specific software configuration settings. In addition, there's a counterpart key named HKLM\Software\Microsoft\Windows that provides an equivalent to the Win95 key with the same name. The Windows 2000 shell (which, of course, is largely based on the Windows NT 4 shell's code) makes heavy use of this key for tracking where applications are installed and how they can be uninstalled when needed. 2.2.1.3.1 SOFTWARE\PoliciesGroup policy objects can store their settings in four distinct keys, three of which are under HKLM. Policy settings that are new for Windows 2000 (say, for instance, the setting that controls whether the user is forcibly logged off or not when her smartcard is removed) generally live under HKLM\Software\Policies. User-specific settings live in HKCU\Software\Policies. What about the things you could set with the SPE from NT 4.0? Most of these settings were moved to the GPOs, which means you modify them through the Group Policy snap-in. In Windows NT they were stored under HKLM\Software\Microsoft\Windows\CurrentVersion or HKLM\Software\Microsoft\Windows NT\CurrentVersion; in Windows 2000, they're stored in a new subkey called Policies under one of those two keys. As you'll see later in the chapter, settings in the GPO can still be applied to the Registry, just as they are with the SPE. 2.2.1.4 SYSTEMThe SYSTEM subkey contains a potpourri of critical data. If HKLM is the most important part of the Registry, SYSTEM is its most important subkey. It has four subkeys that merit further discussion:
2.2.1.4.1 SYSTEM\CurrentControlSetCurrentControlSet is almost, but not quite, a link to whatever control set was used to boot the machine. The kernel copies the current control set (as pointed to by the SYSTEM\Select key) to the CurrentControlSet and Clone keys early in the boot process. System services, control panels, and well-behaved applications use CurrentControlSet instead of using a particular ControlSetXXX key, since it may move or even be deleted without the application's knowledge. The structure of CurrentControlSet is thus identical to any of the ControlSetXXX keys; for convenience, I'll describe it since that's the actual subtree NT uses while running:
2.2.2 Major Subkeys of HKCUThe user profiles stored under HKCU are actually made up of data from ten major subkeys. Since the values under these keys control most of the environment and desktop settings that NT lets you customize, it's worth examining each of these subkeys. 2.2.2.1 AppEventsThe AppEvents subkey stores the mappings between system events (new mail arrived, window maximized, Windows logout, and so on) and sounds. You set these mappings with the Sound control panel; in addition to the system events, applications can define their own events (Visual C++ defines "compilation done"). When a listed event occurs, NT can look in HKCU\AppEvents and play the appropriate sound. 2.2.2.2 ConsoleConsole stores the console window properties you set with the Console control panel or the "Command Line" Properties dialog available from the console window itself. When you change the default command-line window's size, position, buffer size, or font, those changes are stored here. 2.2.2.3 Control PanelControl Panel doesn't directly store anything; instead, it's a placeholder for the system's control panels. Each control panel that wants to store persistent settings on a per-user basis can create its own subkey under HKU\Control Panel and use it however it wants. Control panels that manage systemwide settings, such as the Network and System panels, store their settings in subkeys of HKLM. 2.2.2.4 EnvironmentEnvironment holds the user-defined environment variables set in the Environment Variables dialog (triggered by the button of the same name on the System control panel's Advanced tab). Systemwide environment variables are kept in HKLM\System\CurrentControlSet\Control\Session Manager\Environment.[9] Interestingly, when you make changes to the user-environment variables, the changes don't take effect until you log off and back on, but changes to the system's environment variables take effect immediately (though applications that use environment settings may need to be restarted to pick up the changes).
2.2.2.5 IdentitiesIf you're using Outlook Express or MSN Messenger, the Identities subkey contains subkeys for each mailbox or message recipient identity. This allows multiple users to share an Outlook Express installation, keeping each individual "personality" separate from the others. 2.2.2.6 Keyboard LayoutKeyboard Layout retains the user's preferred keyboard layout. If you're used to the standard U.S. English layout you may not know that, like the Mac, Windows 2000 supports international keyboards whose layouts are different from the standard QWERTY layout. For example, the standard French keyboard's upper row starts with AZERTY. Windows 2000 needs to know the physical layout of the keyboard so it can map keystrokes to the appropriate character codes, especially since you can switch between input locales on the fly. 2.2.2.7 PrintersThe Printers key has two subkeys. Settings stores the user's default print settings, including the name of the default printer and whatever page-setup parameters the user has set. Connections contains one subkey for each installed printer to which the current user can print. If no printers have been defined, this key is either empty or missing, since Windows 2000 creates it the first time a printer's created. Once a printer's been defined, a new subkey named after the print server and printer (for example, ARMORY,HP5M Postscript) appears under Connections. The new subkey's values store the name of the printer driver DLL used with the printer and the name of the print server (if any) that shares the printer to other users. 2.2.2.8 Remote AccessThis subkey holds settings used by the Dial-Up Networking system. 2.2.2.9 SoftwareSoftware, like Control Panel, is a placeholder for a set of subkeys. The exact list of subkeys varies, since any software vendor can create program-specific keys. Applications are supposed to use HKCU\Software for user-specific settings (such as the location of private mail folders) and keep their systemwide settings in HKLM\Software; however, many applications don't have any systemwide settings, so they keep everything under HKCU\Software. 2.2.2.10 SYSTEMIt might seem that HKCU and HKLM\SYSTEM would mix about as well as motor oil and Perrier. Normally, that's true; however, Windows 2000 allows users to set some per-user options that override settings that usually live in HKLM. For example, the spiffy new Windows 2000 Backup utility lets you specify which files not to back up; if you override the default settings for a particular user, HKCU\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToBackup contains that user's list of files to be excluded. Likewise, other applications and components can store settings in HKCU\SYSTEM if they override corresponding settings somewhere in HKLM. It turns out that this subkey exists only when an application (such as Windows 2000 Backup) creates it. A brand-new 2000 installation doesn't have this key. 2.2.2.11 OtherUNICODE Program Groups holds program group settings from previous versions of NT installed on the machine. This key is always present, but on machines that have never had a pre-4.0 version of NT, it is empty. On machines that have been upgraded from NT 3.x to NT 4.0, it contains information about the defined user and system Program Manager groups, but the key's main purpose under NT 4.0 is as a placeholder for backward compatibility. The Volatile Environment key stores per-user environment settings that change between logon sessions. The only key NT 4.0 routinely creates here is LogonServer, which points to the computer that validated the user's logon. On Windows NT systems that were upgraded from Windows 3.x, there is a Windows 3.1 Migration Status subkey under HKCU. This subkey, which is also present on NT machines upgraded from Windows 3.x to NT to Windows 2000, stores the contents of the original REG.INI file, as well as assorted settings from other INI files. NT can automatically map INI files to sections in the Registry, making it possible for 16-bit applications to automatically use the Registry without being rewritten. (For more information on building your own mappings, see Section 9.2 in Chapter 9.) 2.2.3 Major Subkeys of HKCCHKCC was originally introduced in Windows 95, and it appeared in NT 4.0 strictly to allow Win95 applications that use HKCC to run under NT. Windows NT and 2000 both support the concept of multiple hardware profiles; a profile is just a small set of Registry keys that define the hardware available to the computer. The most often-cited example for which hardware profiles are useful is that of a laptop. Let's say you buy a fancy laptop and a docking station, then install Windows 2000 on it. You can use the laptop in three configurations:
Each configuration can be stored as a unique hardware profile. When you boot Windows 2000, you can tell it which one to use, and Windows 2000 loads the appropriate drivers and settings. All the machine's hardware profiles are stored in the Hardware Profiles subkey of control sets under the HKLM\System tree. More importantly, system components and applications that are savvy enough to know about HKCC can query it to see what kind of hardware is currently installed. HKCC contains two subkeys: Software and System\CurrentControlSet. These are sufficient to store the individual profile settings; as you learned earlier in the chapter, CurrentControlSet actually stores driver settings. In addition, HKCC stores the settings that are different from the default. If you use a profile that adds devices not present in the default profile, they are added in HKCC and merged with the default set. 2.2.4 What About the Other Root Keys?At this point, you might be wondering why this chapter doesn't discuss the major subkeys of HKCR, HKPD, and HKU. The real reason is that none of these root keys has any particularly interesting subkeys under them! HKPD is opaque and can't be browsed. HKCR has many subkeys, each of which has the same format and similar contents, and it's only a link to portions of HKLM\Software\Classes anyway. Finally, HKU 's structure and contents are described earlier in this chapter in Section 2.2.2. The subkeys discussed in that section are the real meat of the Registry; for more details on individual subkeys not covered here, see Chapter 11. One interesting difference in Windows 2000 is that class data is split between HKCR and HKCU\Classes, at least from the OS' point of view. Users and applications, though, see a single seamless set of class registrations because Windows 2000 merges HKCR and HKCU\Classes so that a query under HKCR actually queries both of them. |