PC Clean & Optimize Command (CMD)
Best windows cleaning command service
Safe and secure
@echo off
:: Relaunch this script inside PowerShell
Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
:: ================= ADMIN CHECK =================
net session >nul 2>&1
if %errorlevel% neq 0 (
echo Requesting administrative privileges via PowerShell...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"Start-Process '%ComSpec%' -ArgumentList '/c \"\"%~f0\"\"' -Verb RunAs"
exit /b
)
:: ================= CONTINUE SCRIPT =================
echo Running as Administrator...
:: ================= VARIABLES =================
set "TODAY=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%"
set "NOW=%TIME: =0%"
set "NOW=%NOW:~0,2%%NOW:~3,2%"
set "LOGFILE=%SystemDrive%\PC_Cleanup_%TODAY%_%NOW%.log"
:: ================= START =================
echo Cleanup started %DATE% %TIME% > "%LOGFILE%"
:: TEMP FILES
del /f /s /q "%TEMP%\*" 2>nul
del /f /s /q "%SystemRoot%\Temp\*" 2>nul
:: PREFETCH
del /f /q "%SystemRoot%\Prefetch\*" 2>nul
:: RECENT FILES
del /f /q "%APPDATA%\Microsoft\Windows\Recent\*" 2>nul
del /f /q "%APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations\*" 2>nul
del /f /q "%APPDATA%\Microsoft\Windows\Recent\CustomDestinations\*" 2>nul
:: RECYCLE BIN
powershell -Command "Clear-RecycleBin -Force" >nul 2>&1
:: Clear Prefetch Files
del /q /f /s %SystemRoot%\Prefetch\*
:: Clear Thumbnail Cache
del /f /s /q /a %LocalAppData%\Microsoft\Windows\Explorer\thumbcache_*.db
:: PRINT SPOOLER
net stop spooler >nul 2>&1
del /f /q "%SystemRoot%\System32\spool\PRINTERS\*" 2>nul
net start spooler >nul 2>&1
:: Clear Windows Store Cache
wsreset.exe >nul 2>&1
:: Clear Windows Update Cache
net stop wuauserv >nul 2>&1
rd /s /q %SystemRoot%\SoftwareDistribution
net start wuauserv >nul 2>&1
:: Clear Recycle Bin
rd /s /q %SystemDrive%\$Recycle.bin
:: DISK CLEANUP
cleanmgr /verylowdisk
cleanmgr /sageset:1 >nul 2>&1
cleanmgr /sagerun:1 >nul 2>&1
:: WINDOW UPDATE
echo Clearing Event Logs...
for %%G in (Application System Security) do wevtutil cl %%G >nul 2>&1
:: Clear System Restore Points (Optional)
echo Clearing all system restore points...
vssadmin delete shadows /all /quiet >nul 2>&1
:: EVENT LOG
echo Clearing Event Logs...
for %%G in (Application System Security) do wevtutil cl %%G >nul 2>&1
:: Clear DNS Cache
ipconfig /flushdns >nul 2>&1
ipconfig /release
ipconfig /renew
netsh int ip reset
netsh winsock reset
netsh interface tcp set global autotuninglevel=disabled
netsh interface tcp set global autotuninglevel=normal
netsh int tcp set global fastopen=enabled
netsh interface ip set dns name="Wi-Fi" static 1.1.1.1
netsh interface ip add dns name="Wi-Fi" 1.0.0.1 index=2
netsh interface tcp show global
netsh int tcp set global rss=enabled
netsh int tcp set global chimney=enabled
:: FIREWALL RESET DEFAULT
netsh advfirewall reset
:: Clear Windows Logs (Optional)
for /F "tokens=*" %%1 in ('wevtutil.exe el') DO wevtutil.exe cl "%%1" >nul 2>&1
:: Clear Windows Error Reports
echo Clearing Windows Error Reports...
rd /s /q %SystemDrive%\ProgramData\Microsoft\Windows\WER
:: Clear Chocolatey Cache (if installed)
echo Clearing Chocolatey cache (if installed)...
if exist "%ProgramData%\chocolatey" (
rd /s /q "%ProgramData%\chocolatey\lib-bkp"
rd /s /q "%ProgramData%\chocolatey\.chocolatey"
echo Chocolatey cache cleared.
)
:: Clear Windows Logs (Optional)
echo Clearing Windows logs...
for /F "tokens=*" %%1 in ('wevtutil.exe el') DO wevtutil.exe cl "%%1" >nul 2>&1
echo Freeing unused RAM...
RUNDLL32.EXE advapi32.dll,ProcessIdleTasks
powershell -Command "$p = Get-Process; $p | ForEach-Object { [System.GC]::Collect(); [System.GC]::WaitForPendingFinalizers(); $_.Dispose() }"
:: SYSTEM FILE CHECK
sfc /scannow
DISM /Online /Cleanup-Image /RestoreHealth
:: REGISTRY BOOST
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Serialize" /v StartupDelayInMSec /t REG_DWORD /d 0 /f
reg add "HKCU\Control Panel\Desktop" /v MenuShowDelay /t REG_SZ /d 100 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" /v EnablePrefetcher /t REG_DWORD /d 3 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" /v EnableSuperfetch /t REG_DWORD /d 0 /f
:: DISK DEFRAGMENT
defrag C: /O /U /V
echo Your PC successfully cleaned and optimized ! %DATE% %TIME% >> "%LOGFILE%"
echo DONE. Log saved to %LOGFILE%
pause
Comments
Post a Comment
Thanks for your Comments.