ITOnLife

A man who comes from HK work at a IT company, small potato staff

Monday, October 05, 2020

Clear RDP History (Delete Registry key from command line)


@echo off
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default" /va /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers" /f
reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers"
attrib -s -h %userprofile%\documents\Default.rdp
del %userprofile%\documents\Default.rdp
del /f /s /q /a %AppData%\Microsoft\Windows\Recent\AutomaticDestinations
exit
clear rdp history.bat download link: MEGA



Reg command allows us to delete registry keys and registry values from command line. This reg command can be used from batch files also. The syntax for the delete operation is explained below with examples.

Delete a registry value

reg delete  Registry_key_path /v Registry_value_name
Example:
Delete the registry value ‘CleanShutdown‘ under the key ‘HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
c:\> reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer /v CleanShutdown
Delete the registry value CleanShutdown (Yes/No)? yes
The operation completed successfully.
If you want to delete registry key without being prompted for confirmation then add /f switch to the command.
reg delete  Registry_key_path /v Registry_value_name /f
Example:
For the above example, the command to delete the registry value without any confirmation prompt:
c:\> reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer /v CleanShutdown  /f
The operation completed successfully.
If the registry key has space in its name, you can use double quotes as below.
reg delete "Registry_key_path" /v Registry_value_name /f
Example:
Command to delete the registry value ‘TSAdvertise‘ under the registry key ‘HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server’
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v TSAdvertise /f

Delete a registry key

Delete all registry keys and values under a registry key:
reg delete Registry_key_path
Example:
Delete all the registry values under the key ‘HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Favorites’
reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Favorites
Delete all registry values under a registry key
 reg delete RegistryKey  /va

No comments:

Post a Comment