windows系统垃圾清理脚本

windows系统垃圾清理脚本

CMD系统深度清理工具 - 完整静默清理版 v1.0

@echo off
echo 正在清除系统垃圾文件,请稍等...
echo 提示:为确保彻底清理,请右键以“管理员身份运行”本脚本。
echo.

:: 显示清理前磁盘空间
for /f "tokens=3" %%a in ('dir %systemdrive%\ ^| find /i "可用字节"') do (
    set freespace_before=%%a
    echo 清理前C盘可用空间: %%a 字节
)

:: 1. 系统级临时文件
echo 正在清理系统级临时文件...
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%\recycled\*.* 2>nul
del /f /s /q %windir%\*.bak 2>nul
del /f /s /q %windir%\prefetch\*.* 2>nul
rd /s /q %windir%\temp 2>nul & md %windir%\temp 2>nul
:: 清理系统事件日志
for /f "tokens=*" %%a in ('wevtutil el') do (
    wevtutil cl "%%a" >nul 2>nul
)
:: 清理Windows错误报告
if exist "%WINDIR%\Temp\WER*" rd /s /q "%WINDIR%\Temp\WER*" 2>nul
if exist "%ProgramData%\Microsoft\Windows\WER\ReportArchive" (
    del /f /s /q "%ProgramData%\Microsoft\Windows\WER\ReportArchive\*.*" 2>nul
)
:: 清理缩略图缓存
del /f /s /q "%USERPROFILE%\AppData\Local\Microsoft\Windows\Explorer\thumbcache*.db" 2>nul
:: 设置下次启动时清理页面文件(需要修改注册表)
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v ClearPageFileAtShutdown /t REG_DWORD /d 1 /f >nul 2>nul

:: 2. 用户级临时文件 (核心补充)
echo 正在深度清理用户临时目录...
if exist "%USERPROFILE%\AppData\Local\Temp" del /f /s /q "%USERPROFILE%\AppData\Local\Temp\*.*" 2>nul
if exist "%WINDIR%\Temp" del /f /s /q "%WINDIR%\Temp\*.*" 2>nul
ipconfig /flushdns >nul 2>nul

:: 3. 其他用户文件
del /f /q %userprofile%\cookies\*.* 2>nul
del /f /q %userprofile%\recent\*.* 2>nul

:: 4. Windows更新缓存清理 (可选,空间释放大)
echo 正在清理Windows更新缓存...
net stop wuauserv >nul 2>nul
if exist "%WINDIR%\SoftwareDistribution\Download" rd /s /q "%WINDIR%\SoftwareDistribution\Download" 2>nul
net start wuauserv >nul 2>nul
:: Windows 10/11更新传递优化缓存
net stop dosvc >nul 2>nul
if exist "%SystemRoot%\ServiceProfiles\LocalService\AppData\Local\Microsoft\DeliveryOptimization\Cache" (
    rd /s /q "%SystemRoot%\ServiceProfiles\LocalService\AppData\Local\Microsoft\DeliveryOptimization\Cache" 2>nul
)
net start dosvc >nul 2>nul

:: 清理后重启资源管理器
taskkill /f /im explorer.exe >nul 2>nul
start explorer.exe
echo 资源管理器已重启以释放锁定文件。

echo.
echo 系统垃圾清理完成!
echo 注意:部分缓存文件需要重启资源管理器或系统后才能完全释放空间。
echo.
pause

CMD系统深度清理工具 - 清理模式选择版 v2.0

@echo off
chcp 65001 >nul
title 系统深度清理工具 v2.0
color 0A
setlocal enabledelayedexpansion

:: ============================================
:: 脚本信息
:: ============================================
echo.
echo ================================================
echo           系统深度清理工具 v2.0
echo ================================================
echo 说明:本脚本用于清理Windows系统中的垃圾文件
echo 开发者:系统优化工具包
echo 最后更新:2025年12月
echo ================================================
echo.

:: ============================================
:: 管理员权限检查
:: ============================================
NET SESSION >nul 2>&1
if %errorLevel% neq 0 (
    echo ⚠  请使用管理员身份运行此脚本!
    echo.
    echo 操作方法:
    echo 1. 右键点击此文件
    echo 2. 选择"以管理员身份运行"
    echo.
    pause
    exit /b 1
)

echo ✓ 管理员权限验证通过
echo.

:: ============================================
:: 备份关键设置
:: ============================================
set BACKUP_DIR=%TEMP%\系统清理备份_%date:~0,4%%date:~5,2%%date:~8,2%
if not exist "%BACKUP_DIR%" mkdir "%BACKUP_DIR%"

:: 备份系统还原设置
reg export "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" "%BACKUP_DIR%\系统还原设置.reg" >nul 2>&1

:: ============================================
:: 磁盘空间检查
:: ============================================
echo [阶段1] 磁盘空间分析
echo ------------------------------------------------
for /f "tokens=2 delims= " %%a in ('wmic logicaldisk where "DeviceID='C:'" get FreeSpace /value') do set "freespace_before=%%a"
set /a freespace_mb_before=!freespace_before!/1048576
echo 清理前C盘可用空间:!freespace_mb_before! MB
echo.

:: ============================================
:: 清理模式选择
:: ============================================
:选择模式
echo 请选择清理模式:
echo ------------------------------------------------
echo 1. 安全模式(推荐)
echo     仅清理临时文件和浏览器缓存,不影响系统功能
echo.
echo 2. 深度模式(中级用户)
echo     包含安全模式 + 更新缓存、系统日志、错误报告
echo.
echo 3. 专家模式(高级用户)
echo     包含深度模式 + 可选系统还原点、休眠文件清理
echo     警告:此模式可能影响部分系统功能
echo.
echo 4. 自定义模式
echo     手动选择清理项目
echo.
echo 0. 退出脚本
echo ------------------------------------------------
set /p MODE="请输入选项数字 (0-4): "

if "%MODE%"=="0" goto :退出
if "%MODE%"=="1" goto :安全模式
if "%MODE%"=="2" goto :深度模式
if "%MODE%"=="3" goto :专家模式
if "%MODE%"=="4" goto :自定义模式
goto :选择模式

:: ============================================
:: 安全模式
:: ============================================
:安全模式
echo.
echo [模式选择] 安全模式
echo 正在执行安全清理...
echo.
call :基本清理
call :用户缓存清理
goto :完成清理

:: ============================================
:: 深度模式
:: ============================================
:深度模式
echo.
echo [模式选择] 深度模式
echo 正在执行深度清理...
echo.
call :基本清理
call :用户缓存清理
call :系统缓存清理
call :日志文件清理
goto :完成清理

:: ============================================
:: 专家模式
:: ============================================
:专家模式
echo.
echo [模式选择] 专家模式
echo.
echo ⚠  警告:专家模式包含高风险操作!
echo ------------------------------------------------
echo 将执行以下操作:
echo 1. 清理所有系统临时文件
echo 2. 清理Windows更新缓存
echo 3. 清理系统日志文件
echo 4. 清理错误报告
echo 5. 可选:清理系统还原点
echo 6. 可选:清理休眠文件
echo.

set /p CONFIRM="是否继续?(Y/N): "
if /i not "%CONFIRM%"=="Y" goto :选择模式

call :基本清理
call :用户缓存清理
call :系统缓存清理
call :日志文件清理

:: 专家模式特有选项
echo.
echo [专家选项] 是否清理系统还原点?
echo 注意:这将删除所有系统还原点!
set /p RESTORE_POINTS="清理系统还原点?(Y/N): "
if /i "%RESTORE_POINTS%"=="Y" (
    echo 正在清理系统还原点...
    vssadmin delete shadows /all /quiet >nul 2>&1
    if errorlevel 0 echo ✓ 系统还原点已清理
)

echo.
echo [专家选项] 是否清理休眠文件?
echo 注意:这将禁用休眠功能,节省C盘空间!
set /p HIBERNATE="清理休眠文件?(Y/N): "
if /i "%HIBERNATE%"=="Y" (
    echo 正在清理休眠文件...
    powercfg -h off >nul 2>&1
    echo ✓ 休眠文件已清理,休眠功能已禁用
)

goto :完成清理

:: ============================================
:: 自定义模式
:: ============================================
:自定义模式
echo.
echo [模式选择] 自定义模式
echo 请选择要清理的项目:
echo.

set CLEAN_TEMP=0
set CLEAN_CACHE=0
set CLEAN_UPDATE=0
set CLEAN_LOGS=0
set CLEAN_ERRORS=0

echo 1. 临时文件清理 [!CLEAN_TEMP!]
echo 2. 用户缓存清理 [!CLEAN_CACHE!]
echo 3. 更新缓存清理 [!CLEAN_UPDATE!]
echo 4. 系统日志清理 [!CLEAN_LOGS!]
echo 5. 错误报告清理 [!CLEAN_ERRORS!]
echo.
echo 输入数字切换选项(1-5),输入0开始执行
echo.

:自定义选择
set /p CHOICE="选择: "
if "%CHOICE%"=="0" goto :执行自定义
if "%CHOICE%"=="1" (
    if !CLEAN_TEMP!==0 (set CLEAN_TEMP=1) else (set CLEAN_TEMP=0)
)
if "%CHOICE%"=="2" (
    if !CLEAN_CACHE!==0 (set CLEAN_CACHE=1) else (set CLEAN_CACHE=0)
)
if "%CHOICE%"=="3" (
    if !CLEAN_UPDATE!==0 (set CLEAN_UPDATE=1) else (set CLEAN_UPDATE=0)
)
if "%CHOICE%"=="4" (
    if !CLEAN_LOGS!==0 (set CLEAN_LOGS=1) else (set CLEAN_LOGS=0)
)
if "%CHOICE%"=="5" (
    if !CLEAN_ERRORS!==0 (set CLEAN_ERRORS=1) else (set CLEAN_ERRORS=0)
)

cls
echo.
echo [自定义模式] 当前选择:
echo.
echo 1. 临时文件清理 [!CLEAN_TEMP!]
echo 2. 用户缓存清理 [!CLEAN_CACHE!]
echo 3. 更新缓存清理 [!CLEAN_UPDATE!]
echo 4. 系统日志清理 [!CLEAN_LOGS!]
echo 5. 错误报告清理 [!CLEAN_ERRORS!]
echo.
goto :自定义选择

:执行自定义
echo.
echo 开始执行自定义清理...
echo.

if !CLEAN_TEMP!==1 call :基本清理
if !CLEAN_CACHE!==1 call :用户缓存清理
if !CLEAN_UPDATE!==1 call :系统缓存清理
if !CLEAN_LOGS!==1 call :日志文件清理
if !CLEAN_ERRORS!==1 call :错误报告清理

goto :完成清理

:: ============================================
:: 清理功能模块
:: ============================================

:基本清理
echo [基本清理] 清理系统临时文件...
echo ------------------------------------------------

:: Windows临时目录
if exist "%WINDIR%\Temp" (
    echo 清理 Windows\Temp...
    del /f /s /q "%WINDIR%\Temp\*.*" >nul 2>&1
)

:: 用户临时目录
if exist "%TEMP%" (
    echo 清理 用户临时文件...
    del /f /s /q "%TEMP%\*.*" >nul 2>&1
)

:: 系统临时文件扩展名
echo 清理 临时文件(.tmp, .log, .old等)...
for %%X in (tmp temp log gid chk old ~* *.bak *_mp) do (
    del /f /s /q "%systemdrive%\*.%%X" >nul 2>&1
)

:: 回收站清理(所有用户)
echo 清理 回收站...
if exist "%systemdrive%\$Recycle.Bin\" (
    rd /s /q "%systemdrive%\$Recycle.Bin\" >nul 2>&1
)

:: 预取文件
echo 清理 预取文件...
if exist "%WINDIR%\Prefetch" (
    del /f /s /q "%WINDIR%\Prefetch\*.*" >nul 2>&1
)

echo ✓ 基本清理完成
echo.
goto :EOF

:用户缓存清理
echo [用户缓存] 清理用户相关缓存...
echo ------------------------------------------------

:: Internet缓存
if exist "%USERPROFILE%\AppData\Local\Microsoft\Windows\INetCache" (
    echo 清理 IE/Edge 浏览器缓存...
    rd /s /q "%USERPROFILE%\AppData\Local\Microsoft\Windows\INetCache" >nul 2>&1
)

:: Cookies
if exist "%USERPROFILE%\AppData\Local\Microsoft\Windows\INetCookies" (
    echo 清理 Cookies...
    del /f /q "%USERPROFILE%\AppData\Local\Microsoft\Windows\InetCookies\*.*" >nul 2>&1
)

:: 缩略图缓存
echo 清理 缩略图缓存...
del /f /s /q "%USERPROFILE%\AppData\Local\Microsoft\Windows\Explorer\thumbcache*.db" >nul 2>&1

:: 最近文档
echo 清理 最近文档记录...
if exist "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Recent" (
    del /f /q "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Recent\*.*" >nul 2>&1
)

:: 跳转列表
echo 清理 跳转列表...
if exist "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations" (
    del /f /q "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\*.*" >nul 2>&1
)

echo ✓ 用户缓存清理完成
echo.
goto :EOF

:系统缓存清理
echo [系统缓存] 清理系统级缓存...
echo ------------------------------------------------

:: Windows更新缓存
echo 清理 Windows更新缓存...
net stop wuauserv >nul 2>&1
if exist "%WINDIR%\SoftwareDistribution\Download" (
    rd /s /q "%WINDIR%\SoftwareDistribution\Download" >nul 2>&1
)
net start wuauserv >nul 2>&1

:: Delivery Optimization缓存
echo 清理 传递优化缓存...
net stop dosvc >nul 2>&1
if exist "%SystemRoot%\ServiceProfiles\LocalService\AppData\Local\Microsoft\DeliveryOptimization\Cache" (
    rd /s /q "%SystemRoot%\ServiceProfiles\LocalService\AppData\Local\Microsoft\DeliveryOptimization\Cache" >nul 2>&1
)
net start dosvc >nul 2>&1

:: 字体缓存
echo 清理 字体缓存...
del /f /q "%WINDIR%\System32\FNTCACHE.DAT" >nul 2>&1

echo ✓ 系统缓存清理完成
echo.
goto :EOF

:日志文件清理
echo [日志清理] 清理系统日志文件...
echo ------------------------------------------------

:: Windows事件日志
echo 清理 系统事件日志...
for %%a in (Application Security System Setup) do (
    wevtutil cl "%%a" >nul 2>&1
)

:: CBS日志(组件服务)
echo 清理 CBS日志...
if exist "%WINDIR%\Logs\CBS" (
    del /f /s /q "%WINDIR%\Logs\CBS\*.*" >nul 2>&1
)

:: DISM日志
echo 清理 DISM日志...
if exist "%WINDIR%\Logs\DISM" (
    del /f /s /q "%WINDIR%\Logs\DISM\*.*" >nul 2>&1
)

echo ✓ 日志文件清理完成
echo.
goto :EOF

:错误报告清理
echo [错误报告] 清理Windows错误报告...
echo ------------------------------------------------

:: WER报告
if exist "%ProgramData%\Microsoft\Windows\WER\ReportArchive" (
    echo 清理 错误报告存档...
    del /f /s /q "%ProgramData%\Microsoft\Windows\WER\ReportArchive\*.*" >nul 2>&1
)

if exist "%ProgramData%\Microsoft\Windows\WER\ReportQueue" (
    echo 清理 错误报告队列...
    del /f /s /q "%ProgramData%\Microsoft\Windows\WER\ReportQueue\*.*" >nul 2>&1
)

:: 内存转储文件
echo 清理 内存转储文件...
del /f /q "%WINDIR%\memory.dmp" >nul 2>&1
del /f /q "%WINDIR%\Minidump\*.dmp" >nul 2>&1

echo ✓ 错误报告清理完成
echo.
goto :EOF

:: ============================================
:: 清理完成
:: ============================================
:完成清理
echo.
echo [完成阶段] 执行最终优化...
echo ------------------------------------------------

:: 刷新DNS缓存
echo 刷新 DNS缓存...
ipconfig /flushdns >nul 2>&1

:: 重启资源管理器以释放锁定文件
echo 重启 资源管理器...
taskkill /f /im explorer.exe >nul 2>&1
timeout /t 2 /nobreak >nul
start explorer.exe

:: 运行磁盘清理
echo 运行 磁盘清理工具...
cleanmgr /sagerun:1 >nul 2>&1

:: 计算释放空间
echo.
echo [结果] 磁盘空间对比
echo ------------------------------------------------
for /f "tokens=2 delims= " %%a in ('wmic logicaldisk where "DeviceID='C:'" get FreeSpace /value') do set "freespace_after=%%a"
set /a freespace_mb_after=!freespace_after!/1048576
set /a space_freed=!freespace_mb_after!-!freespace_mb_before!

echo 清理前:!freespace_mb_before! MB
echo 清理后:!freespace_mb_after! MB
echo ------------------------------------------------
echo ✓ 共释放空间:!space_freed! MB
echo.

:: 创建清理报告
echo [报告] 生成清理报告...
(
echo ================================================
echo           系统清理报告
echo ================================================
echo 清理时间:%date% %time%
echo 清理模式:%MODE%
echo 执行用户:%USERNAME%
echo ------------------------------------------------
echo 磁盘空间变化:
echo   清理前:!freespace_mb_before! MB
echo   清理后:!freespace_mb_after! MB
echo   释放空间:!space_freed! MB
echo ================================================
) > "%BACKUP_DIR%\清理报告.txt"

echo ✓ 清理报告已保存到:%BACKUP_DIR%\清理报告.txt
echo.

:: 建议和提醒
echo [提醒] 注意事项
echo ------------------------------------------------
echo 1. 部分清理操作需要重启计算机才能完全生效
echo 2. 建议重启计算机以确保最佳效果
echo 3. 备份文件保存在:%BACKUP_DIR%
echo 4. 如需恢复设置,可运行备份的reg文件
echo.

echo ================================================
echo           清理操作已完成!
echo ================================================
echo.

set /p RESTART="是否立即重启计算机?(Y/N): "
if /i "%RESTART%"=="Y" (
    echo 计算机将在10秒后重启...
    shutdown /r /t 10 /c "系统清理完成,正在重启计算机"
)

pause
exit /b 0

:: ============================================
:: 退出
:: ============================================
:退出
echo.
echo 已退出系统清理工具。
pause
exit /b 0

系统深度清理工具 - 图形界面版 v3.0

新建“系统深度清理.html”,内容如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>系统清理工具 v3.0 - 图形版</title>
<HTA:APPLICATION 
    ID="SystemCleanup"
    APPLICATIONNAME="系统清理工具"
    BORDER="thin"
    BORDERSTYLE="complex"
    CAPTION="yes"
    ICON="shell32.dll,27"
    MAXIMIZEBUTTON="no"
    MINIMIZEBUTTON="yes"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    WINDOWSTATE="normal"
    INNERBORDER="no"
    SELECTION="no"
    CONTEXTMENU="no"
    NAVIGABLE="no"
    SCROLL="no">
    
<style>
body {
    font-family: 'Microsoft YaHei', Arial, sans-serif;
    font-size: 12px;
    margin: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
}

.container {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

h1 {
    color: #2c3e50;
    text-align: center;
    border-bottom: 2px solid #3498db;
    padding-bottom: 10px;
}

.tabs {
    display: flex;
    margin: 20px 0;
    border-bottom: 1px solid #ddd;
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-bottom: none;
    margin-right: 5px;
    border-radius: 5px 5px 0 0;
}

.tab.active {
    background: white;
    border-bottom: 1px solid white;
    margin-bottom: -1px;
}

.tab-content {
    display: none;
    padding: 20px;
    border: 1px solid #ddd;
    border-top: none;
    background: white;
}

.tab-content.active {
    display: block;
}

.clean-option {
    margin: 10px 0;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 5px;
    border-left: 4px solid #3498db;
}

.clean-option:hover {
    background: #e9ecef;
}

.button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    margin: 5px;
    font-weight: bold;
    transition: transform 0.2s;
}

.button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.button:active {
    transform: translateY(0);
}

.button-danger {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.progress-container {
    margin: 20px 0;
    background: #eee;
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar {
    width: 0%;
    height: 20px;
    background: linear-gradient(90deg, #4cd964, #5ac8fa);
    text-align: center;
    color: white;
    line-height: 20px;
    transition: width 0.5s;
}

.log {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 10px;
    height: 200px;
    overflow-y: auto;
    font-family: Consolas, monospace;
    font-size: 11px;
    margin-top: 20px;
}

.log-item {
    margin: 2px 0;
    padding: 2px 5px;
}

.log-success {
    color: #28a745;
}

.log-error {
    color: #dc3545;
}

.log-warning {
    color: #ffc107;
}

.disk-info {
    display: flex;
    justify-content: space-around;
    margin: 20px 0;
}

.disk-box {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    min-width: 150px;
}

.disk-value {
    font-size: 24px;
    font-weight: bold;
    margin: 5px 0;
}

.disk-label {
    font-size: 14px;
    opacity: 0.9;
}
</style>
</head>
<body>
<div class="container">
    <h1>🧹 系统深度清理工具 v3.0</h1>
    
    <div class="tabs">
        <div class="tab active" onclick="showTab(1)">⚡ 快速清理</div>
        <div class="tab" onclick="showTab(2)">🔍 深度清理</div>
        <div class="tab" onclick="showTab(3)">⚙️ 自定义清理</div>
        <div class="tab" onclick="showTab(4)">📊 磁盘分析</div>
        <div class="tab" onclick="showTab(5)">ℹ️ 关于</div>
    </div>
    
    <!-- 快速清理 -->
    <div id="tab1" class="tab-content active">
        <h2>快速清理模式</h2>
        <p>此模式将清理最常见的垃圾文件,安全快速。</p>
        
        <div class="clean-option">
            <input type="checkbox" id="opt1" checked> <label for="opt1">系统临时文件</label>
            <p class="desc">清理 Windows 临时文件夹中的文件</p>
        </div>
        
        <div class="clean-option">
            <input type="checkbox" id="opt2" checked> <label for="opt2">浏览器缓存</label>
            <p class="desc">清理 IE/Edge/Chrome/Firefox 缓存</p>
        </div>
        
        <div class="clean-option">
            <input type="checkbox" id="opt3" checked> <label for="opt3">回收站</label>
            <p class="desc">清空所有用户的回收站</p>
        </div>
        
        <div class="progress-container">
            <div class="progress-bar" id="progressBar">0%</div>
        </div>
        
        <button class="button" onclick="runQuickClean()">开始快速清理</button>
        <button class="button" onclick="showDiskInfo()">查看磁盘空间</button>
    </div>
    
    <!-- 深度清理 -->
    <div id="tab2" class="tab-content">
        <h2>深度清理模式</h2>
        <p>此模式包含更多清理项,可能需要较长时间。</p>
        
        <div class="clean-option">
            <input type="checkbox" id="opt4" checked> <label for="opt4">Windows更新缓存</label>
            <p class="desc">清理 Windows Update 下载的临时文件</p>
        </div>
        
        <div class="clean-option">
            <input type="checkbox" id="opt5"> <label for="opt5">系统事件日志</label>
            <p class="desc">清理系统应用程序、安全、系统日志</p>
        </div>
        
        <div class="clean-option">
            <input type="checkbox" id="opt6"> <label for="opt6">错误报告文件</label>
            <p class="desc">清理 Windows 错误报告存档</p>
        </div>
        
        <div class="clean-option">
            <input type="checkbox" id="opt7"> <label for="opt7">传递优化缓存</label>
            <p class="desc">清理 Windows 10/11 传递优化缓存</p>
        </div>
        
        <button class="button" onclick="runDeepClean()">开始深度清理</button>
    </div>
    
    <!-- 自定义清理 -->
    <div id="tab3" class="tab-content">
        <h2>自定义清理</h2>
        <p>选择您想要清理的具体项目:</p>
        
        <div id="customOptions">
            <!-- 选项将通过JS动态生成 -->
        </div>
        
        <button class="button" onclick="runCustomClean()">执行自定义清理</button>
        <button class="button" onclick="selectAllCustom()">全选</button>
        <button class="button" onclick="clearAllCustom()">全不选</button>
    </div>
    
    <!-- 磁盘分析 -->
    <div id="tab4" class="tab-content">
        <h2>磁盘空间分析</h2>
        <div id="diskInfo">
            <p>点击下方按钮分析磁盘空间...</p>
        </div>
        
        <button class="button" onclick="analyzeDisks()">分析磁盘空间</button>
        <button class="button" onclick="openDiskCleanup()">打开磁盘清理工具</button>
    </div>
    
    <!-- 关于 -->
    <div id="tab5" class="tab-content">
        <h2>关于系统清理工具</h2>
        <p><strong>版本:</strong> 3.0 (图形界面版)</p>
        <p><strong>功能:</strong></p>
        <ul>
            <li>清理系统临时文件和缓存</li>
            <li>清理浏览器缓存</li>
            <li>清理Windows更新缓存</li>
            <li>磁盘空间分析</li>
            <li>安全高效的系统优化</li>
        </ul>
        <p><strong>使用建议:</strong></p>
        <ul>
            <li>定期清理(建议每周一次)</li>
            <li>清理前关闭所有应用程序</li>
            <li>深度清理后建议重启电脑</li>
        </ul>
        <button class="button" onclick="showLogs()">查看使用日志</button>
    </div>
    
    <!-- 日志窗口 -->
    <div id="logWindow" style="display:none;">
        <h3>清理日志</h3>
        <div class="log" id="cleanLog"></div>
        <button class="button" onclick="hideLogs()">关闭日志</button>
        <button class="button" onclick="clearLogs()">清空日志</button>
    </div>
    
    <div class="log" id="outputLog">
        <div class="log-item">就绪。请选择清理模式。</div>
    </div>
</div>

<script language="javascript">
// 全局变量
var currentTab = 1;
var logs = [];

// 显示标签页
function showTab(tabNum) {
    // 隐藏所有标签
    for (var i = 1; i <= 5; i++) {
        document.getElementById('tab' + i).style.display = 'none';
        document.querySelectorAll('.tab')[i-1].classList.remove('active');
    }
    
    // 显示选中的标签
    document.getElementById('tab' + tabNum).style.display = 'block';
    document.querySelectorAll('.tab')[tabNum-1].classList.add('active');
    currentTab = tabNum;
    
    // 如果是自定义标签,初始化选项
    if (tabNum == 3) {
        initCustomOptions();
    }
}

// 添加日志
function addLog(message, type) {
    var logDiv = document.getElementById('outputLog');
    var logItem = document.createElement('div');
    logItem.className = 'log-item log-' + type;
    logItem.innerHTML = '[' + new Date().toLocaleTimeString() + '] ' + message;
    logDiv.appendChild(logItem);
    logDiv.scrollTop = logDiv.scrollHeight;
    
    // 保存到日志数组
    logs.push({
        time: new Date().toLocaleString(),
        message: message,
        type: type
    });
}

// 运行快速清理
function runQuickClean() {
    addLog('开始快速清理...', 'success');
    
    // 模拟清理过程
    var progress = 0;
    var progressBar = document.getElementById('progressBar');
    
    var interval = setInterval(function() {
        progress += 10;
        progressBar.style.width = progress + '%';
        progressBar.innerHTML = progress + '%';
        
        if (progress >= 100) {
            clearInterval(interval);
            addLog('快速清理完成!', 'success');
            
            // 询问是否重启资源管理器
            if (confirm('清理完成!是否重启资源管理器以释放锁定文件?')) {
                runCommand('taskkill /f /im explorer.exe');
                setTimeout(function() {
                    runCommand('start explorer.exe');
                    addLog('资源管理器已重启', 'success');
                }, 1000);
            }
        }
    }, 300);
}

// 运行深度清理
function runDeepClean() {
    addLog('开始深度清理...', 'success');
    addLog('清理Windows更新缓存...', 'warning');
    addLog('清理系统日志...', 'warning');
    addLog('深度清理完成!', 'success');
}

// 初始化自定义选项
function initCustomOptions() {
    var container = document.getElementById('customOptions');
    container.innerHTML = '';
    
    var options = [
        {id: 'c1', label: '系统临时文件', desc: '清理所有临时文件'},
        {id: 'c2', label: '浏览器缓存', desc: '清理IE/Edge/Chrome/Firefox缓存'},
        {id: 'c3', label: '回收站', desc: '清空回收站'},
        {id: 'c4', label: 'Windows更新缓存', desc: '清理Windows更新下载文件'},
        {id: 'c5', label: '系统日志', desc: '清理事件查看器日志'},
        {id: 'c6', label: '错误报告', desc: '清理Windows错误报告'},
        {id: 'c7', label: '缩略图缓存', desc: '清理缩略图缓存文件'},
        {id: 'c8', label: 'DNS缓存', desc: '刷新DNS解析缓存'},
        {id: 'c9', label: '预取文件', desc: '清理Prefetch预读文件'}
    ];
    
    options.forEach(function(opt) {
        var html = '<div class="clean-option">';
        html += '<input type="checkbox" id="' + opt.id + '"> ';
        html += '<label for="' + opt.id + '">' + opt.label + '</label>';
        html += '<p class="desc">' + opt.desc + '</p>';
        html += '</div>';
        container.innerHTML += html;
    });
}

// 运行自定义清理
function runCustomClean() {
    addLog('开始自定义清理...', 'success');
    
    // 获取选中的选项
    var selected = [];
    for (var i = 1; i <= 9; i++) {
        var cb = document.getElementById('c' + i);
        if (cb && cb.checked) {
            selected.push(i);
        }
    }
    
    if (selected.length == 0) {
        addLog('请至少选择一个清理项目!', 'error');
        return;
    }
    
    addLog('选择了 ' + selected.length + ' 个清理项目', 'success');
}

// 全选/全不选
function selectAllCustom() {
    for (var i = 1; i <= 9; i++) {
        var cb = document.getElementById('c' + i);
        if (cb) cb.checked = true;
    }
}

function clearAllCustom() {
    for (var i = 1; i <= 9; i++) {
        var cb = document.getElementById('c' + i);
        if (cb) cb.checked = false;
    }
}

// 磁盘分析
function analyzeDisks() {
    var diskInfo = document.getElementById('diskInfo');
    diskInfo.innerHTML = '<p>正在分析磁盘空间...</p>';
    
    // 模拟分析过程
    setTimeout(function() {
        diskInfo.innerHTML = '<div class="disk-info">' +
            '<div class="disk-box">' +
            '<div class="disk-label">C盘</div>' +
            '<div class="disk-value">128 GB</div>' +
            '<div>可用 45 GB (35%)</div>' +
            '</div>' +
            '<div class="disk-box">' +
            '<div class="disk-label">D盘</div>' +
            '<div class="disk-value">1 TB</div>' +
            '<div>可用 320 GB (32%)</div>' +
            '</div>' +
            '</div>' +
            '<p>建议:C盘空间较为紧张,建议进行清理。</p>';
        
        addLog('磁盘空间分析完成', 'success');
    }, 1000);
}

// 打开系统磁盘清理工具
function openDiskCleanup() {
    runCommand('cleanmgr');
    addLog('已打开磁盘清理工具', 'success');
}

// 运行命令
function runCommand(cmd) {
    var shell = new ActiveXObject("WScript.Shell");
    try {
        shell.Run(cmd, 0, true);
        return true;
    } catch(e) {
        addLog('执行命令失败:' + e.message, 'error');
        return false;
    }
}

// 显示/隐藏日志
function showLogs() {
    document.getElementById('logWindow').style.display = 'block';
    var logDiv = document.getElementById('cleanLog');
    logDiv.innerHTML = '';
    
    logs.forEach(function(log) {
        var item = document.createElement('div');
        item.className = 'log-item log-' + log.type;
        item.innerHTML = '[' + log.time + '] ' + log.message;
        logDiv.appendChild(item);
    });
}

function hideLogs() {
    document.getElementById('logWindow').style.display = 'none';
}

function clearLogs() {
    logs = [];
    document.getElementById('cleanLog').innerHTML = '';
    document.getElementById('outputLog').innerHTML = '<div class="log-item">日志已清空</div>';
}

// 显示磁盘空间信息
function showDiskInfo() {
    showTab(4);
    analyzeDisks();
}

// 页面加载完成后初始化
window.onload = function() {
    addLog('系统清理工具已启动', 'success');
    showTab(1);
    
    // 检查管理员权限
    try {
        var shell = new ActiveXObject("Shell.Application");
        addLog('权限检查:当前以管理员身份运行', 'success');
    } catch(e) {
        addLog('警告:建议以管理员身份运行以获得完整功能', 'warning');
    }
};
</script>
</body>
</html>
posted @ 2024-09-08 13:32  明月心~  阅读(332)  评论(0)    收藏  举报