自动开启Windows Update服务

是这样的,我们公司电脑加域后默认应用关闭Windows Update服务的策略。 并且! 会定期的关掉Windows Update服务 可能管理员不想承担几百台电脑更新的压力以及更新后带来的故障因素?

这也导致我经常更新的时候到一半更新失败了,一个Windows更新居然更新了几天都没有更新好。 那么,迫不得已写了这个脚本,现在贴出来吧。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@echo off
::判断是否以管理员权限运行
"%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" >nul 2>&1
if '%errorlevel%' NEQ '0' (
echo 请求管理员权限...
goto UACPrompt
) else ( goto check )
::UAC提权
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
::如果需要后台执行,不想看到黑框请将下面的语句取消注释,并注释上面的一条
::echo UAC.ShellExecute "%~s0", "", "", "runas", 0 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
::检测Windows Update服务状态
:check
net start | find "Windows Update" >nul
IF ERRORLEVEL 1 goto on
IF ERRORLEVEL 0 goto ok
::运行Windows Update,并回到检查状态
:on
echo Windows Update service is stopped
%SystemRoot%\system32\cmd.exe /c sc config "wuauserv" start= auto
%SystemRoot%\system32\cmd.exe /c net start wuauserv
cls
goto check
::Windows Update运行中,暂停59秒后再次检查状态
:ok
echo Windows Update service is running
ping localhost -n 59 >nul
cls
goto check
Licensed under CC BY-NC-SA 4.0
最后更新于 Dec 21, 2017 13:50 UTC
点击刷新🚌