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.
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.
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.
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.Advertisement
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.