Learn to use Windows registry editor command-line options (original) (raw)

This tutorial explains how to use the regedit tool on the command line and make changes to the Windows registry for advanced administrative jobs.

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

There are times when a simple addition to the Windows registry can fix a stubborn problem to save you from having to reinstall an application or modifying an existing Windows registry key mitigates an emerging threat until Microsoft patches the vulnerability. There are several utilities and techniques to make registry changes. Windows Registry Editor (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.

What is the Windows registry?

The registry is a database feature in the Windows desktop and server OSes used to configure and organize settings on the Windows device 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 (HKCR). This root key tells Windows what application to use when you want to open a certain file type.
  2. HKEY_CURRENT_USER (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 (HKLM). Data in this root key relates to configuration information for the computer or any user.
  4. HKEY_USERS (HKU). This root key holds all the actively loaded profiles for users on the machine.
  5. HKEY_CURRENT_CONFIG (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.

Often, Microsoft directs 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 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 in the Windows search box on the taskbar.

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 lets 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 OS, 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 creates 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.

Regedit command-line parameters and syntax

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

regedit filename.reg Imports a registry file into the Windows registry.
regedit /c filename.reg Creates a new registry file and replaces 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 file name 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 OSes 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 Uses silent mode. It performs an action without stopping for confirmation with dialog box.

How to edit the Windows 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 /? 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 returns a 0 code. If the results are different, reg returns a code of 2. If the operation failed, reg displays a code of 1.
reg copy Copies a registry entry to a specified location on the local or remote computer. Here is an example of its use: reg copy \\RemotePC\HKLM\Software\TestKey HKLM\Software\TestKey. The command copies 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. Here is an example of its use: reg delete HKLM\Software\FakeName\TestApp\Settings. This command deletes the Settings registry key, as well as any subkeys and settings.
reg export Exports named subkeys, entries and values of the local computer into a file. Here is an example of its 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. Here is an example of its 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. Here is an example of its use: reg load HKLM\Test TestHive.hiv. This command loads 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. Here is an example of its 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. Here is an example of its use: reg restore HKLM\Software\Microsoft\Test RegBackup.hiv. This command restores the contents of the RegBackup.hiv file into the Test key.
reg save Exports specified registry subkeys, entries and values into a named file. Here is an example of its 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. Here is an example of its use: reg unload HKLM\TestHive. The command unloads HKLM\TestHive from the registry.

Editor's note: This article was revised in 2024 by TechTarget editors to improve the reader experience.

Dig Deeper on IT operations and infrastructure management