Programming Field

Reg Delete - DOS/Command Prompt Reference

[Windows NT series/XP or later] Deletes registry keys and values. This is one of the operations of Reg command.

This page covers commands that allow you to modify the Windows registry. As the registry contains important settings for Windows, please proceed with caution when making changes. It is strongly recommended to create a backup before manipulating the registry, especially if you are not familiar with registry operations. Making inadvertent changes to various data can lead to Windows not starting up properly. Please note that we cannot take responsibility for any issues that may arise from using the information on this page.

Syntax

reg[.exe] delete <key> [/v <var-name> | /ve | /va]
    [/f] [/reg:[32|64]]

Options

<key>

Specifies the key name. For specific instructions on how to specify the key name, please refer to ‘About specifying key names’.

The key name is specified with the complete path, and if the key does not exist, an error will occur.

/v <var-name> | /ve | va

If using ‘/v <var-name>’, specifies the name of the value you want to delete for <var-name>. The name must be a standalone name and cannot include a pathname (the path should be included in <key>).

If using ‘/ve’, Reg deletes the value of the ‘Default’ (or ‘Standard’, unnamed) value in the specified key. After deletion, the state will be ‘Not set’.

If you specify ‘/va’, it will delete all values contained within the specified key. (Subkeys and their included values will not be deleted.)

If all of options above are omitted, it will delete the specified key and all its values and subkeys.

* Due to this specification, there is no option to delete all subkeys contained within a specific key while preserving that key. (See examples for a method to delete all subkeys.)

/f Deletes without displaying a prompt. If the /f option is omitted, it will prompt to confirm deletion.
/reg:[32|64]

If there is an environment with both 64-bit and 32-bit versions (WOW64), specifying ‘/reg:32’ will reference registry data used by 32-bit applications (for example, ‘HKLM\Software\WOW6432Node’ for HKLM), and specifying ‘/reg:64’ will reference registry data used by 64-bit applications.

If this option is omitted, the executed Reg.exe will reference the registry corresponding to its bit version. If it is a 64-bit version, it will reference the 64-bit registry; if it is a 32-bit version (located under %SystemRoot%\SysWOW64), it will reference the 32-bit registry. If you want to reference registry data for a specific application and know whether it's 32-bit or 64-bit, you can explicitly specify this option to avoid ambiguity.

* Even if Reg.exe is a 32-bit version, you can reference the 64-bit registry by using ‘/reg:64’.
* If you are using the 64-bit version of Reg.exe, you can also directly specify keys such as ‘HKLM\Software\WOW6432Node’ when referencing the 32-bit registry.

Details

Usage of Reg Delete

The ‘DELETE’ command in Reg is used to delete values or keys within the registry. Similar to the Del command for files, be cautious as deletions are irreversible (especially, it is recommended to use the /f option only when the deletion targets are clear, such as in batch processing). Registry data can be backed up in advance using commands like ‘SAVE’ or ‘EXPORT’.

Samples

Sample 1

reg delete "HKCU\Software\My Company\MyApp" /ve

Deletes the ‘Default’ value within the ‘HKEY_CURRENT_USER\Software\My Company\MyApp’ key. (If it doesn't already exist, an error will occur.)

Sample 2 (Batch file)

for /f "delims=\ tokens=1,*" %%K in ('reg query "HKCU\Software\My Company\MyApp\Recent" /f "" /k') do (
    if not "%%L"=="" reg delete "%%K\%%L" /f
)

[Extensions] Deletes all subkeys within the ‘HKEY_CURRENT_USER\Software\My Company\MyApp\Recent’ key. Utilizing Reg Query to output subkeys, the batch retrieves them via the For command and passes them to Reg Delete. Note that Reg Query outputs the total count at the end, so it checks if there is a second or later string delimited by ‘\’ to exclude that (since key names always have a root key, ‘\’ will be present).

See also