How To Delete And Add Registry Keys From The Command Line

Martin Brinkmann
Updated •
Tutorials, Windows

There are a few scenarios where a Windows user might have to or want to use the command line instead of the Regedit tool to change, delete or add keys in the Windows Registry.

It can be that a virus or other malicious software has limited access to the Registry so that regedit cannot be used. Another possible reason is script or batch usage to perform operations like adding or deleting keys regularly by simply executing a batch file on the computer system.

The command line tool reg.exe which ships with the Windows operating system can be used to manage the Registry from the command line. It provides you with access to delete or add but also other options like exporting, comparing or importing keys.

reg.exe: Registry command line tool

Entering reg /? on the command line displays all possible options that are available. You can spawn a command prompt with a tap on the Windows-key, typing cmd.exe and hitting the Enter-key.

Delete a Registry key using the command line

The reg delete command can be used on local and remote machines. The basic command looks like the following

reg delete keyname valuename parameters

To delete a key with all its values and subkeys a user would have to run the following command

reg delete HKLM\Software\Test

That's the most basic form of deleting a Registry key from the command line. This will delete the key Test with all its subkeys and values.

reg delete \\RemoteSystem\HKLM\Software\Test /v Testvalue

This example deletes the Registry value Testvalue under Test on the remote machine RemoteSystem.

Add a Registry key from the command line

The add switch uses a similar structure. The basic command

reg add HKLM\Software\Test

adds the key Test to HKLM\Software\

Important are the \t and \d parameters which define the Regkey data type and the value that is assigned.

reg add HKLM\Software\Test /v Testdata /t REG_BINARY /d ffffff

Adds the value Testdata to the key Test that is of type reg_binary and contains the data ffffff.

Other handy options that reg.exe provides you with include exporting the full Registry or part of it using the /export parameter,  or using the /import parameter to import data to the Registry.

Using the /? parameter explains every command in great detail. This concludes the little tutorial on how to delete and add Registry keys from the command line.

Update: This method works in all supported versions of the Windows operating system.

Comments

  1. Guard said on
    Reply

    This does not work with HEX values!

    If you type A-F it says wrong value.

    1. Duggy Fresh said on
      Reply

      Bit of a late reply, I know, but prefix HEX values with “0x”.

      Duggy.

  2. Hentie said on
    Reply

    Typo on \d:

    reg add HKLM\Software\Test /v Testdata /t REG_BINARY \d ffffff

    should be

    reg add HKLM\Software\Test /v Testdata /t REG_BINARY /d ffffff

    1. Martin Brinkmann said on
      Reply

      Well spotted, thanks and corrected.

  3. Zim said on
    Reply

    Nice! Thanks for the tip :)

Leave a Reply

By commenting, you accept our privacy policy and keep the discussion respectful and on topic.