Skip to main content

Batch Script Deleting from Registry

Deleting from Registry

Deleting from the registry is done via the reg delete command.

note

To delete values from the registry, you must have sufficient privileges on the system to perform this operation.

The reg delete command has the following variants. In the second variant, the default value is removed, and in the last variant, all values under the specified key are removed.

Syntax
reg delete <keyname> [{/v Valuename | /ve | /va}] [/f]

where:

  • <keyname> specifies the full path of the subkey or entry to be added.
    • To specify a remote computer, include the computer name (in the format \\<computername>\) as part of the keyname. Omitting \\<computername>\ causes the operation to default to the local computer.
    • The keyname must include a valid root key. Valid root keys for the local computer are: HKLM, HKCU, HKCR, HKU, and HKCC. If a remote computer is specified, valid root keys are: HKLM and HKU.
    • If the registry key name contains a space, enclose the key name in quotes.
  • /v Valuename deletes a specific entry under the subkey. If no entry is specified, then all entries and subkeys under the subkey will be deleted.
  • /ve specifies that only entries that have no value will be deleted.
  • /va deletes all entries under the specified subkey. Subkeys under the specified subkey are not deleted.
  • /f deletes the existing registry subkey or entry without asking for confirmation.
  • /? displays help at the command prompt.

Examples

To delete the registry key Timeout and its all subkeys and values, type:

reg delete HKLM\Software\MyCo\MyApp\Timeout

To delete the registry value MTU under HKLM\Software\MyCo on the computer named ZODIAC, type:

reg delete \\ZODIAC\HKLM\Software\MyCo /v MTU

To delete a key into the registry under the location HKEY_CURRENT_USER\Console. This key has the name of Test, type:

reg delete HKEY_CURRENT_USER\Console /v Test /f