How to Delete Registry Keys Using a REG File

Windows Registry (.reg) files are commonly used to add or modify registry settings, but they can also be used to automatically delete entire keys or specific values. By adding a simple hyphen (-) symbol to the key path within a properly formatted text file, you can remove target registry keys instantly when importing the file through Regedit.

The Syntax for Deleting a Registry Key

To delete an entire registry key, you must prefix the key path with a hyphen (-) inside the square brackets.

Here is the exact format required:

Windows Registry Editor Version 5.00

[-HKEY_LOCAL_MACHINE\Software\ExampleKey]

When this file is imported, Windows recognizes the minus sign at the beginning of the path and deletes the ExampleKey folder along with all subkeys and values contained inside it.

Step-by-Step Instructions

  1. Open a Text Editor: Open Notepad or any plain text editor.
  2. Add the Header: Type Windows Registry Editor Version 5.00 on the first line, followed by a blank line.
  3. Specify the Key: Enclose the full registry path in square brackets, placing a minus sign - immediately after the opening bracket (for example, [-HKEY_CURRENT_USER\Software\TestKey]).
  4. Save the File:
    • Click File > Save As.
    • Set the “Save as type” dropdown to All Files (.).
    • Name the file with a .reg extension (e.g., delete_key.reg).
  5. Import into the Registry:
    • Double-click the saved .reg file.
    • Click Yes when prompted by User Account Control (UAC).
    • Click Yes to confirm you want to continue modifying the registry.

Alternatively, you can import the file silently via the Command Prompt or PowerShell using the following command:

regedit.exe /s "C:\path\to\delete_key.reg"

Deleting Specific Values Instead of the Entire Key

If you only need to delete a specific value inside a key rather than the entire key itself, place the hyphen after the equals sign for that specific value name:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\ExampleKey]
"ValueToDelete"=-

In this scenario, the ExampleKey remains intact, and only the value named ValueToDelete is removed.