Batch – Install Windows Updates – Suppress Reboots

email me

This script allows you to cycle through any amount of Windows updates (MSUs), and install them silently while suppressing reboots. I was able to install 180+ updates…without rebooting every few updates.

Code

@ECHO OFF
title Administrative Windows Updates
CLS

setlocal enabledelayedexpansion

:START
REM GO TO UPDATES PATH
C:
CD\MS_Updates\

REM SCAN THROUGH INSTALLING EACH UPDATE SILENTLY
FOR %%# IN (*.msu) DO (
Echo Installing Microsoft Update: %%#
C:\Windows\System32\Wusa.exe “%%#” /quiet /norestart
)
ECHO.

:END
ECHO Windows Update is complete!
PING -n 10 127.0.0.1>nul
EXIT

 

Screenshot of the script running (click image to zoom)

 

Notes

If you think you need to update the Wusa, run this:

windowsupdateagent-7.6-x64.exe /quiet /norestart

And, with very little effort, you could throw in cab files

For %%# in (*.cab) Do (

Echo Installing Microsoft Update: %%#
C:\Windows\System32\dism.exe /online /add-package /packagepath:”%%#” /quiet /norestart
)
Or even MSIs…

For %%# in (*.msi) Do (
Echo Installing Microsoft Update: %%#
C:\Windows\System32\msiexec.exe /i “%%#” /quiet /norestart
)

 

It may be the case your MSUs aren’t installing as intended (error 50, error 85, error 87). This is because the cab itself has to be extracted, and then installed.

Here is the code for that (the ‘expand‘ command does it).

@Echo off
title Microsoft Windows Updates
cls

setlocal enabledelayedexpansion

c:
cd C:\setup\PostSetup\Updates_MS
set Updates=C:\setup\PostSetup\Updates_MS
cd "%~dp0"

goto EXP rem expands files


:EXP
echo Scanning MSUs...
For %%# in (*.msu) Do (
    Echo Expanding: %%#
	Expand -F:* %%# %Updates%	
)
echo.

:INSTALL
for /R "%~dp0" %%# IN (*-KB*.MSU) DO (
call :GETFILE %%~n#
echo Installing Windows Update: KB!update!...
start /wait c:\windows\system32\wusa.exe "%%#" /quiet /norestart
C:\Windows\System32\dism /online /add-package /packagepath:"%Updates%\%%#" /quiet /norestart
)

::QUIT
:END
Echo.
Echo Windows Updates are complete^^!
timeout /t 4 >nul
pause
exit /b 0


:GETFILE
SET "update=%*"
FOR /F "DELIMS=-" %%U IN ("%update:*-KB=%") DO SET "update=%%U"

More about Dism