Skip to main content

How to Access all of the Registry Hives with PowerShell

In Windows PowerShell, there is a PSProvider called Registry.  By default, it gives you access to two registry hives.

PS C:\> Get-PSDrive -PSProvider Registry

 

Name         Used (GB)     Free (GB) Provider      Root                                               CurrentLocation

----         ---------     --------- --------     ------------------

HKCU                                 Registry     HKEY_CURRENT_USER

HKLM                                 Registry     HKEY_LOCAL_MACHINE                                                   

 

 

There are actually 5 registry hives.

  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS
  • HKEY_CURRENT_CONFIG

According to Microsoft, here are their intended purposes in life. (http://support.microsoft.com/kb/256986)

Folder/predefined key Description
HKEY_CURRENT_USER Contains the root of the configuration information for the user who is currently logged on. The user's folders, screen colors, and Control Panel settings are stored here. This information is associated with the user's profile. This key is sometimes abbreviated as "HKCU."
HKEY_USERS Contains all the actively loaded user profiles on the computer. HKEY_CURRENT_USER is a subkey of HKEY_USERS. HKEY_USERS is sometimes abbreviated as "HKU."
HKEY_LOCAL_MACHINE Contains configuration information particular to the computer (for any user). This key is sometimes abbreviated as "HKLM."
HKEY_CLASSES_ROOT Is a subkey of HKEY_LOCAL_MACHINE\Software. The information that is stored here makes sure that the correct program opens when you open a file by using Windows Explorer. This key is sometimes abbreviated as "HKCR." Starting with Windows 2000, this 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 override the default settings and 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 programs that are designed for earlier versions of Windows. To change the settings for the interactive user, changes must be made under HKEY_CURRENT_USER\Software\Classes instead of under HKEY_CLASSES_ROOT. To change the default settings, changes must be made under HKEY_LOCAL_MACHINE\Software\Classes. 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.
HKEY_CURRENT_CONFIG Contains information about the hardware profile that is used by the local computer at system startup.

The registry provider gives you access to the three unlisted hives: HKEY_CLASSES_ROOT, HKEY_USERS, and HKEY_CURRENT_CONFIG.  You just have to manually create a drive to them.

 

New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR

New-PSDrive -PSProvider registry -Root HKEY_USERS -Name HKU

New-PSDrive -PSProvider registry -Root HKEY_CURRENT_CONFIG -Name HKCC

 

Once you do, you will have access to these hives just the two default drives the registry provider gives you.

PS C:\> Get-PSDrive -PSProvider Registry

 

Name       Used (GB)     Free (GB) ProviderRoot

----       ---------     --------- --------     ---- 

HKCC                               Registry     HKEY_CURRENT_CONFIG                                   

HKCR                               Registry     HKEY_CLASSES_ROOT                                     

HKCU                               Registry     HKEY_CURRENT_USER                                     

HKLM                               Registry     HKEY_LOCAL_MACHINE                             

HKU                                Registry     HKEY_USERS                                           

 

 

 

Comments

Popular posts from this blog

How to list all the AD LDS instances on a server

AD LDS allows you to provide directory services to applications that are free of the confines of Active Directory.  To list all the AD LDS instances on a server, follow this procedure: Log into the server in question Open a command prompt. Type dsdbutil and press Enter Type List Instances and press Enter . You will receive a list of the instance name, both the LDAP and SSL port numbers, the location of the database, and its status.

How to run GPResult on a remote client with PowerShell

In the past, to run the GPResult command, you would need to either physically visit this client, have the user do it, or use and RDP connection.  In all cases, this will disrupt the user.  First, you need PowerShell remoting enabled on the target machine.  You can do this via Group Policy . Open PowerShell and type this command. Invoke-Command –ScriptBlock {GPResult /r} –ComputerName <ComputerName> Replace <ComputerName> with the name of the target.  Remember, the target needs to be online and accessible to you.