Platform SDK: Registry

The HKEY_CLASSES_ROOT Key

The HKEY_CLASSES_ROOT (HKCR) key contains file extension associations and COM class registration information such as ProgIDs, CLSIDs, and IIDs.

Starting with Windows 2000, class registration and file extension information is stored under both the HKEY_LOCAL_MACHINE key and the HKEY_CURRENT_USER key. The HKEY_LOCAL_MACHINE\Software\Classes key contains default settings that can apply to all users on the local computer. The HKEY_CURRENT_USER\Software\Classes key contains settings that apply only to the interactive user. The HKEY_CLASSES_ROOT key provides a view of the registry that merges the information from these two sources. HKEY_CLASSES_ROOT also provides this merged view for older Win32-based applications that are running on Windows 2000.

The user-specific settings have priority over the default settings. For example, the default setting might specify Microsoft® WordPad as the application that handles .doc files. But each user can override this setting by specifying Microsoft Word or some other word processor in his or her registry hive. The user-specific information is stored in the user's registry hive, which is loaded under HKEY_CURRENT_USER when the user logs on.

There are a number of registry functions, such as RegOpenKeyEx or RegQueryValueEx, for which you can specify the HKEY_CLASSES_ROOT key. When you call these functions from a process running in the security context of the interactive user, the system merges the default settings in HKEY_LOCAL_MACHINE\Software\Classes with the interactive user's settings at HKEY_CURRENT_USER\Software\Classes. For more information on how these settings are merged, see Merged View of HKEY_CLASSES_ROOT.

To change the settings for the interactive user, write the changes under HKEY_CURRENT_USER\Software\Classes rather than using the HKEY_CLASSES_ROOT key. To change the default settings, write to HKEY_LOCAL_MACHINE\Software\Classes. If you write keys or values to the HKEY_CLASSES_ROOT key, the system by default stores the information under HKEY_LOCAL_MACHINE\Software\Classes. However, if the key to be written to already exists under HKEY_CURRENT_USER\Software\Classes, the information is stored under HKEY_CURRENT_USER. Suppose, for example, you try to create a key named B under the HKEY_CLASSES_ROOT\CLSID\A key. If the HKEY_CURRENT_USER\Software\Classes\CLSID\A key already exists, the new key is created under HKEY_CURRENT_USER, and HKEY_LOCAL_MACHINE is unchanged. However, if HKEY_CURRENT_USER\Software\Classes\CLSID\A key does not exist, the new key is created under HKEY_LOCAL_MACHINE, and HKEY_CURRENT_USER is unchanged.

Processes running in a security context other than that of the interactive user should not use the HKEY_CLASSES_ROOT key with registry functions such as RegOpenKeyEx or RegQueryValueEx. Instead, such processes can explicitly open the HKEY_LOCAL_MACHINE\Software\Classes key to access the default settings. To open a registry key that merges the contents of HKEY_LOCAL_MACHINE\Software\Classes with the settings for a specified user, these processes can call the RegOpenUserClassesRoot function. For example, a thread that is impersonating a client can call RegOpenUserClassesRoot if it needs to retrieve a merged view for the client being impersonated. Note that RegOpenUserClassesRoot fails if the user profile for the specified user has not been loaded. The system automatically loads the profile for the interactive user when logging on. For other users, you need to call the LoadUserProfile function to explicitly load the user's profile.

For Windows NT 4.0 and earlier, and Windows 95/ 98, HKEY_CLASSES_ROOT is an alias for the HKEY_LOCAL_MACHINE\Software\Classes key. All users share the information in HKEY_LOCAL_MACHINE. For computers with multiple users, this means that all users have the same file extension associations and COM class registrations.