Is “HKLM” an alias for “HKEY_LOCAL_MACHINE”?

61

3

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?

Joe Kearney

Posted 2014-10-08T11:47:57.683

Reputation: 775

Answers

79

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.)

Twinkles

Posted 2014-10-08T11:47:57.683

Reputation: 704

3This is the correct answer. The full names are the only ones supported by the kernel. Any abbreviations are tool-specific. – nobody – 2014-10-08T14:21:27.450

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 – 2014-10-08T23:13:59.747

1also you can't use these abbreviations in .reg files, you have to write full name inside the square scopes there – None – 2014-10-09T18:38:02.763

@LightnessRacesinOrbit Feel free to produce some evidence proving it wrong. – nobody – 2014-10-10T16:00:21.503

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)

Kunal

Posted 2014-10-08T11:47:57.683

Reputation: 1 769

17This 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 – 2014-10-09T08:03:24.930

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 – 2014-10-10T20:06:32.813

Although they are the same thing, the abbreviation is not part of the standard and therefore not pure equivalent. – None – 2014-10-11T20:24:17.193

3

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.

Steven Penny

Posted 2014-10-08T11:47:57.683

Reputation: 7 294

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).

Joe

Posted 2014-10-08T11:47:57.683

Reputation: 242