Getty Images

Tip

Use command-line options to edit registries with regedit.exe

Did you know this venerable Windows GUI tool has several switches for basic registry editing tasks? See what tweaks Microsoft inserted in regedit for administrative use.

There are a multitude of hidden settings in the Windows operating system that you can unlock with help from several tools designed for Windows registry editing.

There are times when a simple addition to the registry can fix a stubborn problem to save you from having to reinstall an application, or modifying an existing registry key can ward off an emerging threat until Microsoft deploys an official patch to plug the vulnerability.

There are several utilities and techniques to make registry changes. Regedit is one of the oldest tools, but Microsoft provides several more options, including the command-line utilities named reg and regini, PowerShell cmdlets and the Group Policy administrative tool.

Back to basics: What is the Windows registry?

The registry is a Windows OS database feature used to configure and organize the information related to settings for the operating system for the users, installed software and hardware devices. The registry replaced the need to use configuration files in application folders. One benefit to the registry is to reduce issues from faulty program updates that corrupted configuration files.

The registry in the latest versions of Windows has a default of five predefined keys:

  1. HKEY_CLASSES_ROOT (shortened name HKCR). This root key tells Windows what application to use when you want to open a certain file type.
  2. HKEY_CURRENT_USER (shortened name HKCU). This root key holds data related to the user currently using the machine, including the user's folders and screen colors.
  3. HKEY_LOCAL_MACHINE (shortened name HKLM). Data in this root key relates to configuration information for the computer or any user.
  4. HKEY_USERS (shortened name HKU). This root key holds all the actively loaded profiles for users on the machine.
  5. HKEY_CURRENT_CONFIG (shortened name HKCC). This root key holds hardware profile information the machine calls during system startup.

Below each key can be multiple subkeys and values. Not every application requires a subkey.

Oftentimes, Microsoft will direct administrators to mitigate a pressing security issue in Windows by modifying subkeys in the registry by adding new registry values -- also called data entries -- or modifying or existing ones.

One common Windows registry edit is changing the file association for a certain file type so it opens with a specific application. For example, if you want .html files to open with Google Chrome rather than Microsoft Edge, you can adjust those settings in the file extension area of the Windows registry.

Regedit.exe uses

Regedit is the GUI-based tool built into Windows for editing the Windows registry. To start, type regedit from the Windows run or search box.

Regedit gives a visual representation of the Windows registry, using a dual-pane layout with the root keys and subkeys in the left pane and the values for the selected key or subkey in the right pane. You can import or export registry subkeys and values from the File menu. From the Edit menu, you can create a new entry in the registry, check the permissions for the selection, delete or rename the selection, or copy the key name. You can also run a search from this menu.

Right-clicking in the different sections let you add a new key, modify an existing one or delete a key.

regedit layout
The regedit registry editor is a GUI-based tool that displays the hierarchical layout of the Windows registry. It also includes several command-line options.

Due to its importance to the Windows operating system, you should export a backup of the registry in case you need to recover from a problem. Use the export function in the regedit File menu to make a backup of the entire registry or just the section you plan to edit. This will create a .reg file. If a problem occurs, you can double-click on that .reg file to restore the original settings.

Microsoft released its first 64-bit Windows Server version with Server 2008 and its first Windows client 64-bit version with Windows 8. The default version of regedit in the latest versions of Windows can open both 64-bit and 32-bit registry keys for backward compatibility.

Command-line options and syntax for regedit.exe

You can regedit with either hotkeys or a mouse, but the utility has several command-line options for basic registry work.

regedit

filename.reg

Imports a registry file into the Windows registry.

regedit

/c filename.reg

Create a new registry file and replace existing entries in the Windows registry.

regedit

/d registry-subkey

Removes a subkey from the registry, such as regedit /d HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default.

regedit

/e

Exports the entire registry to a file. You can modify this command to add a filename and specific location on the drive, such as regedit /e c:\AllRegistryEntries.reg. You can export a specific key with the following example command regedit /e keybackup.reg HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Edge.

regedit

/l: system

Specify the location of the SYSTEM.DAT file used in legacy Windows operating systems and typically stored in the C:\Windows folder. This file stores the data kept in the HKEY_LOCAL_MACHINE key in the registry.

regedit

/r:user

Specify the location of the NTUSER.DAT file to use. This is the backup of the HKEY_USERS key in the registry. The file is typically found in the C:\Users\username folder.

regedit

/m

Opens an additional regedit instance, which can be helpful when troubleshooting to compare registry entries.

regedit

/s

Silent mode. Performs an action without stopping for confirmation with dialog box.

How to edit a registry using the command line

While regedit can be used on the command line, it is not optimal for granular administrative work. To make repeatable changes to the registry in multiple machines with automation, it's worth looking into switching from regedit to reg, a command-line-based tool included with Windows.

The reg utility offers more expansive functionality to edit subkeys and their values from the command line. Reg is more flexible and works well for a range of administrative scenarios, such as using batch files to correct common issues in client machines and managing the registry on a remote machine.

reg add parameter
The reg command has 11 parameters, each with its own set of flags that provide additional functionality. The screenshot shows the help menu for the reg add parameter, which includes its flags and examples of how to use the parameter.

To use reg, type cmd from the Windows run or search box to open the command prompt.

To show all the parameters for the reg command, enter reg /? from the command prompt. Typing reg <parameter> /? shows the switches available for the parameter and examples of how to use them.

Parameter

Description

reg add

Inserts a new subkey or entry to the registry. The following example shows how to add a key to remote Windows system named RemotePC: reg add \\RemotePC \HKLM\Software\Test

reg compare

Runs a comparison of specified registry subkeys or entries. The following example compares all values under the named keys: reg compare HKLM\Software\Test\MyApp HKLM\Software\Test\SaveMyApp. If the results are identical, reg will return a 0 code. If the results are different, reg will return a code of 2. If the operation failed, reg will display a code of 1.

reg copy

Copies a registry entry to a specified location on the local or remote computer. Example of use: reg copy \\RemotePC\HKLM\Software\TestKey HKLM\Software\TestKey. The command will copy the TestKey values in the registry from the remote machine named RemotePC to the current machine.

reg delete

Removes a subkey or entries from the registry. Example of use: reg delete HKLM\Software\FakeName\TestApp\Settings. This command deletes the Settings registry key, and any subkeys and settings.

reg export

Exports named subkeys, entries and values of the local computer into a file. Example of use: reg export HKLM\Software\FakeName\TestApp BackupFile.reg. The command makes a copy of the TestApp key and its subkeys and values in a file name BackupFile.reg.

reg import

Copies the contents of a file that contains exported registry subkeys, entries and values into the registry of the local computer. Example of use: reg import BackupFile.reg. The command adds BackupFile.reg registry entries to the machine.

reg load

Writes saved subkeys and entries into a different subkey in the registry. Example of use: reg load HKLM\Test TestHive.hiv. This command will load the TestHive.hiv file into the HKLM\Test key.

reg query

Returns a list of the next tier of subkeys and entries that are located under a specified subkey in the registry. Example of use: reg query HKLM\Software > C:\regoutput.txt. This command outputs the subkeys of HKLM\Software into a file named regoutput.txt in the C:\ folder.

reg restore

Imports subkeys and entries from a file into the registry. Example of use: reg restore HKLM\Software\Microsoft\Test RegBackup.hiv. This command will restore the contents of the RegBackup.hiv file into the Test key.

reg save

Exports specified registry subkeys, entries and values into a named file. Examples of use: reg save HKLM\Software\Test\AppTest BackupFile.hiv. The command saves the AppTest hive to the BackupFile.hiv file.

reg unload

Removes the registry section loaded by the reg load operation. Example of use: reg unload HKLM\TestHive. The command unloads HKLM\TestHive from the registry.

Dig Deeper on Microsoft messaging and collaboration

Cloud Computing
Enterprise Desktop
Virtual Desktop
Close