Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HKEY_LOCAL_MACHINE\SOFTWARE\Classes vs HKEY_CLASSES_ROOT

Tags:

registry

In Microsoft's documentation, I found the following paragraph

The HKEY_LOCAL_MACHINE\SOFTWARE\Classes key corresponds to the HKEY_CLASSES_ROOT key, which was retained for compatibility with earlier versions of COM.

Now, I am not sure which key the which in that paragraph refers to: the HKLM\SOFTWARE\Classes or the HKCU key.

I'd appreciate if someone could clarify.

like image 993
René Nyffenegger Avatar asked Dec 31 '18 06:12

René Nyffenegger


1 Answers

HKEY_CLASSES_ROOT (abbrev. HKCR, not to be confused with HKCU, HKEY_CURRENT_USER) is a merged view of the ...\Software\Classes sub hierarchies in HKLM and HKCU.

This is actually documented, although it is not linked from the COM docs you refer to:

HKEY_CLASSES_ROOT Key:

Class registration and file name extension information is stored under both the HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER keys. 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 applications designed for previous versions of Windows.

They even go into the details of this merge mess, but if you need any specific behavior from the merged view, you would be well advised to verify it, because the details are rather messy in my opinon:

  • For reading, essentially most of the stuff is merged, that is you will see both keys and both values from overlapping keys.
  • When you have the same value in both, you will most likely see the one from HKCU, not from HKLM.
  • When you have the same/overlapping key in both, you will see its merged values and subkeys. (Or so I think.) (At least on Win7.)
  • When you write via HKCR, it will depend on whether you are admin or not. And whether you run under UAC or not. Do try not to write via HKCR, it will make your life easier.
    • Specifically, I'm referring to this gem (which is what you can actually observe):

      If you write keys to a key under HKEY_CLASSES_ROOT, the system stores the information under HKEY_LOCAL_MACHINE\Software\Classes.

      If you write values to a key under HKEY_CLASSES_ROOT, and the key already exists under HKEY_CURRENT_USER\Software\Classes, the system will store the information there instead of under HKEY_LOCAL_MACHINE\Software\Classes.

like image 58
Martin Ba Avatar answered Oct 15 '22 22:10

Martin Ba