windows更新缓存清理脚本可自动停止相关服务、清空softwaredistribution\download、windows\temp和winsxs\temp目录,避免误删根目录导致系统异常,支持管理员运行与定时任务集成。
windows 系统更新后,windows update 会把补丁安装包(如 .cab、.msu 文件)和临时解压内容保留在 c:\windows\softwaredistribution\download 和 c:\windows\temp 等位置,长期积累可能占用数 gb 空间。批处理脚本能自动停止相关服务、清空目录、重置缓存状态,无需手动操作。
关键清理目标与风险提示
主要清理路径包括:
-
C:\Windows\SoftwareDistribution\Download\*(补丁下载缓存) -
C:\Windows\Temp\*(系统临时文件,含部分更新中间文件) -
C:\Windows\WinSxS\Temp\*(组件存储临时数据,可安全清空子目录)
注意:不要删除 SoftwareDistribution 根目录本身(否则 Windows Update 会重建但可能报错),也不要清空 WinSxS 主目录(含系统组件,误删会导致系统损坏)。
编写可直接运行的清理批处理脚本
新建文本文档,粘贴以下内容,另存为 clean_wu_cache.bat(编码选 ANSI 或 UTF-8 with BOM),右键以“管理员身份运行”:
@echo off
title Windows 更新缓存自动清理
setlocal enabledelayedexpansion
echo 正在停止 Windows Update 相关服务...
net stop wuauserv >nul 2>&1
net stop cryptSvc >nul 2>&1
net stop bits >nul 2>&1
net stop msiserver >nul 2>&1
echo 清理 SoftwareDistribution\Download...
if exist "C:\Windows\SoftwareDistribution\Download\" (
del /q /f "C:\Windows\SoftwareDistribution\Download\*" >nul 2>&1
for /d %%i in ("C:\Windows\SoftwareDistribution\Download\*") do rd /s /q "%%i" >nul 2>&1
)
echo 清理 Windows\Temp...
del /q /f "C:\Windows\Temp\*" >nul 2>&1
for /d %%i in ("C:\Windows\Temp\*") do rd /s /q "%%i" >nul 2>&1
echo 清理 WinSxS\Temp...
if exist "C:\Windows\WinSxS\Temp\" (
del /q /f "C:\Windows\WinSxS\Temp\*" >nul 2>&1
for /d %%i in ("C:\Windows\WinSxS\Temp\*") do rd /s /q "%%i" >nul 2>&1
)
echo 重启 Windows Update 服务...
net start wuauserv >nul 2>&1
net start cryptSvc >nul 2>&1
net start bits >nul 2>&1
net start msiserver >nul 2>&1
echo.
echo ✅ 清理完成。共释放空间请手动查看磁盘属性。
pause
增强稳定性与静默执行建议
如需定时自动运行(例如每周一次),可配合任务计划程序使用:
- 在脚本开头添加
if not "%~dp0"=="%SystemRoot%\System32\" echo 请以管理员身份运行 & pause & exit /b防止双击无权限执行失败 - 将
pause替换为timeout /t 5 >nul实现 5 秒自动退出,适合计划任务 - 如需记录清理日志,末尾加一行:
echo [%date% %time%] Cleaned >> C:\clean_log.txt
替代方案:DISM + Storage Sense 组合更彻底
批处理仅清临时缓存;若想连带清理旧版本 Windows 更新文件(如已安装补丁的冗余组件),建议补充运行:
-
dism /online /Cleanup-Image /StartComponentCleanup /ResetBase(重置组件存储,释放 WinSxS 空间) - 开启「设置 > 系统 > 存储 > 存储感知」并配置自动清理临时文件
这两步建议单独执行或集成进脚本末尾(需额外管理员权限且耗时较长)。











