删除远程连接记录和运行框记录-bat批处理

windows11 为例  

@echo off
 
REM 删除注册表中的远程桌面连接历史记录
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default" /va /f
reg delete "HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client\Default" /va /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers" /f
 
REM 添加注册表键
reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers"
 
REM 删除 Documents 文件夹下的 Default.rdp 文件
del /ah %homepath%\documents\default.rdp
 
REM 删除运行框的记录
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU" /va /f
del /Q /F %APPDATA%\Microsoft\Windows\Recent\*
echo. > %APPDATA%\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
 
REM 删除某个文件夹里的内容
@echo off
set "folderPath=C:\123\123"
 
if exist "%folderPath%" (
    rmdir /s /q "%folderPath%"
    echo folder ok
) else (
    echo folder none
)
 
REM 删除某个文件夹里的内容
@echo off
set "folderPath=C:\Users\Administrator\AppData\Local\Microsoft\Terminal Server Client"
 
if exist "%folderPath%" (
    rmdir /s /q "%folderPath%"
    echo folder ok
) else (
    echo folder none
)
REM 删除 清理系统事件
  PowerShell -ExecutionPolicy Bypass -File "C:\Users\Administrator\Desktop\ClearEventLogs.ps1"
 
echo all ok
pause