@echo off title 恢复 Windows 自动更新 :: ============================================================ :: 恢复 Windows 自动更新脚本 (CMD/Batch) :: 适用: Windows 10 / 11 :: 必须以管理员身份运行 :: ============================================================ :: ---------- 检查管理员权限 ---------- net session >nul 2>&1 if %errorLevel% neq 0 ( echo [错误] 请以管理员身份运行此脚本! pause exit /b ) echo. echo ============================================ echo 正在恢复 Windows 自动更新... echo ============================================ echo. :: ---------- 1. 恢复服务启动类型 ---------- echo [1/5] 正在恢复更新服务... :: wuauserv:恢复为手动 sc config wuauserv start= demand >nul 2>&1 :: UsoSvc:恢复为自动 sc config UsoSvc start= auto >nul 2>&1 :: WaaSMedicSvc:通过注册表恢复为手动 (Start=3) reg add "HKLM\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc" /v Start /t REG_DWORD /d 3 /f >nul 2>&1 :: BITS:恢复为手动 sc config BITS start= demand >nul 2>&1 :: dosvc:恢复为自动 sc config dosvc start= auto >nul 2>&1 :: 尝试启动服务 net start wuauserv >nul 2>&1 net start UsoSvc >nul 2>&1 net start BITS >nul 2>&1 net start dosvc >nul 2>&1 echo 服务已恢复。 :: ---------- 2. 删除自动更新策略注册表 ---------- echo [2/5] 正在删除自动更新策略... reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoUpdate /f >nul 2>&1 reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v AUOptions /f >nul 2>&1 reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v AlwaysAutoRebootAtScheduledTime /f >nul 2>&1 reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DoNotConnectToWindowsUpdateInternetLocations /f >nul 2>&1 reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v ExcludeWUDriversInQualityUpdate /f >nul 2>&1 echo 注册表策略已清理。 :: ---------- 3. 重新启用计划任务 ---------- echo [3/5] 正在重新启用计划任务... schtasks /change /tn "\Microsoft\Windows\UpdateOrchestrator\Schedule Scan" /enable >nul 2>&1 schtasks /change /tn "\Microsoft\Windows\UpdateOrchestrator\Schedule Scan Static Task" /enable >nul 2>&1 schtasks /change /tn "\Microsoft\Windows\UpdateOrchestrator\UUS Failover Task" /enable >nul 2>&1 schtasks /change /tn "\Microsoft\Windows\WindowsUpdate\Scheduled Start" /enable >nul 2>&1 schtasks /change /tn "\Microsoft\Windows\WindowsUpdate\sih" /enable >nul 2>&1 schtasks /change /tn "\Microsoft\Windows\WindowsUpdate\sihboot" /enable >nul 2>&1 schtasks /change /tn "\Microsoft\Windows\WindowsUpdate\Automatic App Update" /enable >nul 2>&1 schtasks /change /tn "\Microsoft\Windows\InstallService\ScanForUpdates" /enable >nul 2>&1 schtasks /change /tn "\Microsoft\Windows\InstallService\ScanForUpdatesAsUser" /enable >nul 2>&1 echo 计划任务已重新启用。 :: ---------- 4. 清理 hosts 文件 ---------- echo [4/5] 正在清理 hosts 文件... set "hosts=C:\Windows\System32\drivers\etc\hosts" set "temp=%temp%\hosts_clean.tmp" if exist "%hosts%" ( findstr /v /c:"windowsupdate.microsoft.com" /c:"download.microsoft.com" /c:"update.microsoft.com" /c:"windowsupdate.com" /c:"wustat.windows.com" /c:"ntservicepack.microsoft.com" /c:"statsfe2.ws.microsoft.com" /c:"corporate.stats.microsoft.com" "%hosts%" > "%temp%" if exist "%temp%" ( copy /y "%temp%" "%hosts%" >nul 2>&1 del "%temp%" >nul 2>&1 ) ) ipconfig /flushdns >nul 2>&1 echo hosts 文件已清理,DNS 缓存已刷新。 echo. echo ============================================ echo 完成!建议重启电脑使设置完全生效。 echo ============================================ echo. pause