The following article is the third of series about registry and working on it through command line (CMD) and PowerShell. We are going to explain how you can delete registry key with command line and PowerShell. You will be available to delete individually through CMD or over the network through batch file.
Check Also:
How to Edit Registry Key/value with CMD
How to Add Registry Key/value with CMD
How to delete registry key and value with CMD:
Below is the default commands line to delete registry key and “deleteTestKey” on path “HKEY_CURRENT_USER\Software\” – To run it:
- Start
- Search “CMD”
- Run as Administrator
- Execute Below Command
reg delete “HKEY_CURRENT_USER\Software\deleteTestKey” /f
Below is the default command to delete registry value entry “DeleteTestValue” of type “DWORD (32-bit)” on path “HKEY_CURRENT_USER\Software\DeleteTestKey:
- Start
- Search “CMD”
- Run as Administrator
- Execute Below Command
Customized:
reg delete HKEY_CURRENT_USER\Software\DeleteTestKey\ /v DeleteTestValue /f
Default Command:
Reg Delete Regkey /v RegValue /f
Command Description:
- Regkey – Path where the new value should be added.
- RegValue – Name of the value that should be added
- /v – Deletes a specific entry under the subkey. If no entry is specified, then all entries and subkeys under the subkey will be deleted.
How to Delete Registry key and value with PowerShell:
Below is the PowerShell default command to delete registry key “DeleteTestKey” on path “HKEY_CURRENT_USER\Software\” – To run it:
- Start
- Search PowerShell
- Run as Administrator
- Execute Below Command
# Set the location to the registry Set-Location -Path 'HKCU:\Software\' # Remove Key Get-Item -Path 'HKCU:\Software\DeleteTestKey' -Recurse
Below is the PowerShell default command to delete registry value entry “DeleteValue” of type “DWORD (32-bit)” on the path “HKEY_CURRENT_USER\Software\DeleteTestKey\” To run it:
- Start
- Search PowerShell
- Run as Administrator
- Execute Below Command
# Create new items with values Remove-ItemProperty -Path 'HKCU:\Software\DeleteTestKey' -Name ‘DeleteValue" # Get out of the Registry Pop-Location
Note! The –Recurse parameter delete all the subkeys without additional.
If you want to delete all subkeys inside the specified key without deleting the key itself, you should add the “*” symbol at the end of the path:
Remove-Item -Path " HKCU:\Software\DeleteTestKey\*" -Recurse
How to Delete Registry key and value on a remote computer:
Below is the command to remove registry key on a remote computer. To run it:
- Start
- Search “CMD”
- Run as Administrator
- Execute Below Command
REG Delete \\ComputerName\HKCU\Software\DeleteTestKey
Below is the command to remove registry value on a remote computer. To run it:
- Start
- Search “CMD”
- Run as Administrator
- Execute Below Command
REG delete \\ComputerName\HKCU\Software\DeleteTestKey /v DeleteValue
How to delete registry key and value with batch file:
The same commands used above to add the registry key from the command prompt can be integrated on the batch file. The commands can be used on the existing batch along with other commands or on the new batch file. To create a new batch file:
- Open a notepad files
- Write the below command
- Save it as regedit.bat
- Run it with DoubleClick and the command will be executed.
@echo off
reg delete “HKEY_CURRENT_USER\Software\DeleteTestKey” /f
The bat files used mostly when you want to spread it over the network using GPO or SCCM
How to delete registry key and value with regedit file (.reg)
You can delete registry key and value by using .reg file. This file structure can be found by exporting certain keys from the regedit interface by right-clicking on it and the export option. To create it from the screech:
- Open a notepad file
- Copy and paste the below command
- Save it at addkey.reg
Windows Registry Editor Version 5.00 [-HKEY_CURRENT_USER\Software\DeleteTestKey2]
To delete a single value put a hyphen (-) after the equals sign in the .reg file.
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\DeleteTestKey2] "Deletevalue1"=-
The command with delete value “Deletevalue1”. To execute .reg files, double-click it and after typing to the confirmation yes the changes with be done.
Conclusion:
Those are the methods to delete registry key and values using command prompt, PowerShell, and batch files. Follow us for the next articles where we will explain the methods to edit and delete keys and values from the registry