Is “HKLM” an alias for “HKEY_LOCAL_MACHINE”?

HKLM is often used as an abbreviation for HKEY_LOCAL_MACHINE. Somewhat unexpectedly this also appears to be true when I ask reg for a value.

C:\>reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "CurrentVersion"

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    CurrentVersion    REG_SZ    6.1

C:\>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "CurrentVersion"

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    CurrentVersion    REG_SZ    6.1

Existe-t-il un reference asserting that they are equivalent, or that one is an alias for the other? Or are there, en fait, cases where they are not the same thing?


Source : Super User:slight_smile:

No, although HKLM is an abbreviation for HKEY_LOCAL_MACHINE, there is no official statement from Microsoft that it is always equivalent. En fait, it explicitly states that the availability of these shortcuts depend on the software being used and they are generally referred to as “commonly used abbreviations”.

There are cases where abbreviating HKEY_LOCAL_MACHINE to HKLM is not permitted, for instance when defining a policy:

The following conditions apply:

  • Le registre path must be enclosed by percent signs (%).

  • Le registre setting must be a REG_SZ or REG_EXPAND_SZ type. If le registre value contains variable d’environnements, these will be expanded when the policy is evaluated.

  • Do not use HKLM as an abbreviation for HKEY_LOCAL_MACHINE, or HKCU as an abbreviation for HKEY_CURRENT_USER.

  • A registry path rule can also include a suffix path.

(From the documentation of Software restriction policies, boldness added by me.)