60

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

Is there a reference asserting that they are equivalent, or that one is an alias for the other? Or are there, in fact, cases where they are not the same thing?

78

No, although HKLM is an abbreviation for HKEY_LOCAL_MACHINE, there is no official statement from Microsoft that it is always equivalent. In fact, 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:

  1. The registry path must be enclosed by percent signs (%).
  2. The registry setting must be a REG_SZ or REG_EXPAND_SZ type. If the registry value contains environment variables, these will be expanded when the policy is evaluated.
  3. Do not use HKLM as an abbreviation for HKEY_LOCAL_MACHINE, or HKCU as an abbreviation for HKEY_CURRENT_USER.
  4. A registry path rule can also include a suffix path.

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

  • 3
    This is the correct answer. The full names are the only ones supported by the kernel. Any abbreviations are tool-specific. – Andrew Medico Oct 8 '14 at 14:21
  • 13
    > 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" It'd be great if you could link to a source for that. (Not that I don't trust you, but an authoritative source makes the claim stronger.) – Bob Oct 8 '14 at 23:13
  • also you can't use these abbreviations in .reg files, you have to write full name inside the square scopes there – user373230 Oct 9 '14 at 18:38
  • @LightnessRacesinOrbit Feel free to produce some evidence proving it wrong. – Andrew Medico Oct 10 '14 at 16:00
4

Yes.

HKLM stands for HKEY_LOCAL_MACHINE Variable.

And HKCU stands for HKEY_CURRENT_USER.

They are the same thing.

According to Wikipedia:

There are seven predefined root keys, traditionally named according to their constant handles defined in the Win32 API, or by synonymous abbreviations (depending on applications):

  • HKEY_LOCAL_MACHINE or HKLM
  • HKEY_CURRENT_CONFIG or HKCC (only in Windows 9x and NT)
  • HKEY_CLASSES_ROOT or HKCR
  • HKEY_CURRENT_USER or HKCU
  • HKEY_USERS or HKU
  • HKEY_PERFORMANCE_DATA (only in Windows NT, but invisible in the Windows Registry Editor)
  • HKEY_DYN_DATA (only in Windows 9x, and visible in the Windows Registry Editor)
  • 16
    This says that they are colloquially equivalent, but not that they are defined to be the same thing or aliases; in particular "depending on applications". – Joe Kearney Oct 9 '14 at 8:03
  • It's also a mostly-unsourced Wikipedia page, so take that for what it's worth (probably accurate but no better than a SO or SU page realistically, and perhaps worse). – Joe Oct 10 '14 at 20:06
  • Although they are the same thing, the abbreviation is not part of the standard and therefore not pure equivalent. – user366447 Oct 11 '14 at 20:24
4

I would add that with PowerShell, HKLM exists as a mount for HKEY_LOCAL_MACHINE, as such it is mutable. Example

PS > Get-Item HKLM:
Name                           Property
----                           --------
HKEY_LOCAL_MACHINE

PS > Remove-PSDrive HKLM

PS > Get-Item HKLM:
Get-Item : Cannot find drive. A drive with the name 'HKLM' does not exist.
2

As Twinkles notes, it is a commonly used abbreviation. I don't see any source explicitly saying it cannot be used, but I did find a table indicating the commonly used abbreviations for the Windows 2000 registry subtrees, which are mostly the same as the current set (As of Windows 7). Here's what I found out there:

From Registry Overview for Windows 2000 (modified for formatting for this site):

Table 16.1 Registry Subtrees
HKEY_CLASSES_ROOT  HKCR
HKEY_CURRENT_USER HKCU
HKEY_LOCAL_MACHINE HKLM
HKEY_USERS HKU
HKEY_CURRENT_CONFIG HKCC
HKEY_PERFORMANCE_DATA No commonly used abbreviation

That list is presented in an XP support article as well, minus the Performance Data subtree (which I think is now gone and Pankaj/Wikipedia support that thought).

There is also the Windows Registry Reference, which I linked to the Predefined Keys page, which lists the various subtrees, each of which have links to their specific page (most of which go to Windows Server 2003 pages for some reason). They list the abbreviations there as well, which are consistent with the above.

None of these pages discusses whether the abbreviations can be used in programming however, which leads me to believe that isn't explicitly stated anywhere - but is more an unstated rule (don't use abbreviations if you're not sure they will work).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.