Windows長期運行產生海量垃圾文件:臨時文件(*.tmp, *.log)、備份文件(*.bak, *.old)、IE緩存、系統日志、Prefetch、回收站殘留……佔用空間、拖慢性能。一個自製批處理腳本,比收費優化大師更透明、更可控、零廣告、零推廣。
@echo off
chcp 65001 >nul
title 系統垃圾一鍵清理工具 v1.0
color 0A
echo ==========================================
echo 正在清理系統垃圾文件,請稍候...
echo ==========================================
echo.
REM 1. 系統臨時文件
echo [1/8] 清理系統臨時文件 (*.tmp, *_mp, *.log, *.gid, *.chk, *.old, *.bak)...
del /f /s /q "%SystemDrive%\*.tmp" 2>nul
del /f /s /q "%SystemDrive%\*_mp" 2>nul
del /f /s /q "%SystemDrive%\*.log" 2>nul
del /f /s /q "%SystemDrive%\*.gid" 2>nul
del /f /s /q "%SystemDrive%\*.chk" 2>nul
del /f /s /q "%SystemDrive%\*.old" 2>nul
del /f /s /q "%SystemDrive%\*.bak" 2>nul
REM 2. 回收站
echo [2/8] 清空回收站...
rd /s /q "%SystemDrive%\$Recycle.Bin" 2>nul
rd /s /q "%SystemDrive%\RECYCLER" 2>nul
REM 3. Windows臨時目錄
echo [3/8] 清理 Windows\Temp...
rd /s /q "%WinDir%\Temp" 2>nul
md "%WinDir%\Temp" 2>nul
REM 4. Prefetch 預讀緩存
echo [4/8] 清理 Prefetch...
del /f /s /q "%WinDir%\Prefetch\*.*" 2>nul
REM 5. 用戶配置文件臨時文件
echo [5/8] 清理用戶臨時文件...
del /f /s /q "%UserProfile%\Local Settings\Temp\*.*" 2>nul
del /f /s /q "%LocalAppData%\Temp\*.*" 2>nul
REM 6. IE/Edge 緩存
echo [6/8] 清理瀏覽器緩存...
del /f /s /q "%UserProfile%\Local Settings\Temporary Internet Files\*.*" 2>nul
del /f /s /q "%LocalAppData%\Microsoft\Windows\INetCache\*.*" 2>nul
del /f /s /q "%LocalAppData%\Microsoft\Edge\User Data\Default\Cache\*.*" 2>nul
REM 7. Cookies 與 歷史記錄 (可選,取消註釋啟用)
REM del /f /q "%UserProfile%\Cookies\*.*" 2>nul
REM del /f /q "%UserProfile%\Local Settings\History\*.*" 2>nul
REM 8. 最近文件記錄
echo [7/8] 清理最近文件記錄...
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
echo.
echo ==========================================
echo 清理完成!釋放空間統計中...
echo ==========================================
echo.
dir /s /a "%SystemDrive%\*.tmp" "%SystemDrive%\*_mp" "%SystemDrive%\*.log" "%SystemDrive%\*.gid" "%SystemDrive%\*.chk" "%SystemDrive%\*.old" "%SystemDrive%\*.bak" 2>nul | find "File(s)"
echo.
echo 按任意鍵退出...
pause >nul
CleanJunk.bat (編碼選 ANSI 或 UTF-8 with BOM)%SystemRoot%\system32\cleanmgr.exe| 命令 | 參數含義 | 作用 |
|---|---|---|
del | /f 強制刪除只讀 /s 遞歸子目錄 /q 靜默模式 | 刪除匹配文件 |
rd | /s 刪除目錄樹 /q 靜默 | 刪除整個目錄結構 |
md | 重建必要目錄 (如 Temp) | |
2>nul | 重定向錯誤輸出到空設備 | 抑制「找不到文件/訪問拒絕」錯誤提示 |
C:\Windows\SoftwareDistribution)、驅動程序存儲庫 (C:\Windows\System32\DriverStore)註冊表添加自定義清理項,使「磁盤清理」(cleanmgr.exe) 識別腳本清理項目:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Custom_CleanJunk]
@="Custom Junk Cleaner"
"StateFlags0100"=dword:00000001
"Description"="清理系統臨時文件、日志、緩存、回收站等垃圾文件"
"IconPath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,00,6c,00,65,00,61,00,6e,00,6d,00,67,00,72,00,2e,00,65,00,78,00,65,00,00,00
導入後運行 cleanmgr /sageset:100 勾選「Custom Junk Cleaner」,再 cleanmgr /sagerun:100 即可圖形化調用。
自製批處理清理工具,代碼透明可審計、邏輯可定製、無捆綁推廣、資源佔用極低。配合 Storage Sense (Win10/11) / 磁盤清理 / 第三方開源工具 多層防護,讓系統永保「苗條」體態。