C盘清理垃圾文件(2025更新)

说明

脚本会默认以管理原模式运行,弹窗提示获取管理员权限时需要点击确认
在这里插入图片描述

创建console脚本删除文件夹内容

简便 xxx.cmd 如:

@echo off
:: 解决中文乱码
chcp 65001 >nul 2>&1

title Windows 系统垃圾清理
echo.
echo Windows 清空显卡更新安装包, Windows更新文件, 垃圾文件和无效注册表...
echo 请稍等...
echo.

:: 设定默认进入静默模式
set DEBUG_MODE=0
set "DEBUG_OUT=>nul 2>&1" & rem ▶ DEBUG模式关闭时静默输出
if %DEBUG_MODE% equ 1 set DEBUG_OUT=
:: 默认静默模式
:: 如果需要启用调试模式,修改此行为 set DEBUG_MODE=1

:: 检测是否以管理员身份运行
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo 需要管理员权限运行,请稍等...
    powershell -Command "Start-Process '%~0' -Verb RunAs"
    exit
)

:: 询问用户是否禁用 NVIDIA 自动更新
echo 是否禁用 NVIDIA 自动更新?(Y/N)
choice /c YN /m "输入 Y 关闭,输入 N 跳过:"
if %errorlevel%==1 (
    set DISABLE_NVIDIA_UPDATE=1
    echo 将禁用 NVIDIA 自动更新!
) else (
    set DISABLE_NVIDIA_UPDATE=0
    echo 已跳过 NVIDIA 自动更新关闭步骤。
)

:: 进度条函数(调整以允许并行显示调试信息)
call :progress 0

:: 关闭不必要的进程
taskkill /f /im explorer.exe %DEBUG_OUT%
taskkill /f /im dwm.exe %DEBUG_OUT%

call :progress 10

:: 清理 Windows 预取文件
echo 清理 Windows 预取文件...
del /s /f /q C:\Windows\Prefetch\*.* %DEBUG_OUT%

call :progress 25

:: 清理 Windows 临时文件
echo 清理 Windows 临时文件...
del /s /f /q C:\Windows\Temp\*.* %DEBUG_OUT%
del /s /f /q %TEMP%\*.* %DEBUG_OUT%

call :progress 40

:: 清理 Windows 更新缓存
echo 清理 Windows 更新缓存...
net stop wuauserv %DEBUG_OUT%
rd /s /q C:\Windows\SoftwareDistribution\Download %DEBUG_OUT%

:: 清理 DNS 缓存
echo 清理 DNS 缓存...
ipconfig /flushdns %DEBUG_OUT%

call :progress 55

:: 清理 Windows 日志文件
echo 清理 Windows 日志文件...
for /d %%i in (C:\Windows\Logs\*) do rd /s /q "%%i" %DEBUG_OUT%
del /s /f /q C:\Windows\Logs\*.* %DEBUG_OUT%

net start wuauserv %DEBUG_OUT%

call :progress 70

:: 清理 NVIDIA 安装包
rd /s /q "C:\ProgramData\NVIDIA Corporation\Downloader" %DEBUG_OUT%

:: 清理崩溃日志和下载缓存
rd /s /q "C:\Users\%username%\AppData\Local\CrashDumps" %DEBUG_OUT%
rd /s /q "C:\Users\%username%\AppData\Local\Downloaded Installations" %DEBUG_OUT%

call :progress 85

:: 运行磁盘清理工具
echo 运行 Windows 磁盘清理...
cleanmgr /sagerun:1

call :progress 95

:: 根据用户选择禁用 NVIDIA 更新
if %DISABLE_NVIDIA_UPDATE%==1 (
    echo 关闭 NVIDIA 自动更新...
    sc stop NvContainerLocalSystem %DEBUG_OUT%
    sc config NvContainerLocalSystem start= disabled %DEBUG_OUT%
    sc stop NvTelemetryContainer %DEBUG_OUT%
    sc config NvTelemetryContainer start= disabled %DEBUG_OUT%
    schtasks /change /tn "\NVIDIA\NvNodeLauncher" /disable %DEBUG_OUT%
    schtasks /change /tn "\NVIDIA\NvTmMon" /disable %DEBUG_OUT%
    reg add "HKLM\SOFTWARE\NVIDIA Corporation\NvBackend" /v UpdateCheck /t REG_DWORD /d 0 /f %DEBUG_OUT%
    reg add "HKLM\SOFTWARE\Wow6432Node\NVIDIA Corporation\NvBackend" /v UpdateCheck /t REG_DWORD /d 0 /f %DEBUG_OUT%
    echo NVIDIA 自动更新已关闭!
) else (
    echo 已跳过 NVIDIA 自动更新关闭步骤。
)

call :progress 98

:: 修复并优化 Windows 组件存储
echo 优化 Windows 组件存储...
dism /online /cleanup-image /startcomponentcleanup %DEBUG_OUT%

:: 重新创建 Explorer 相关注册表,防止 Explorer 卡死
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs" /f %DEBUG_OUT%
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU" /f %DEBUG_OUT%
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32" /f %DEBUG_OUT%

:: 重新启动 Windows 资源管理器
echo 重新启动 Windows 资源管理器...
start explorer.exe
start dwm.exe

call :progress 100

echo.
echo 清理完成!
pause
exit

:: 进度条函数

:progress
set /a progress=%1
:: 更新进度条并显示调试信息,避免清除屏幕
echo progress: [%progress%%%] 
if %DEBUG_MODE% equ 1 (
    echo --- 调试信息 ---
)
exit /b

几个常见的临时文件路径

(大概几秒就能删光)
C:\Windows\SoftwareDistribution\Download

(显卡的安装包)
C:\Program Files\NVIDIA Corporation\Installer2
C:\ProgramData\NVIDIA Corporation\Downloader

(崩溃信息)
C:\Users%username%\AppData\Local\CrashDumps

(下载安装临时路径)
C:\Users%username%\AppData\Local\Downloaded Installations

(QQ的一些文件)
C:\Users%username%\AppData\Roaming\Tencent\Logs
C:\Users%username%\AppData\Roaming\Tencent\QQ\webkit_cache
C:\Users%username%\AppData\Roaming\Tencent\WeChat\XPlugin

(网易云的缓存)
C:\Users%username%\AppData\Local\Netease\CloudMusic\Cache\Cache

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路途遥远gg

帮到你了就好

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值