Technology
Back to Technology
Batch File To Aid In Troubleshooting Windows Update Issues

By: Gordon Rankine
Published: 10 Apr 2014 20:00

When you are patching numerous Windows servers with Windows Updates via WSUS, sometimes you encounter a few servers that either do not pull any updates down from the WSUS server or just loop when trying to install updates.

There are various solutions online that recommend renaming folders, stopping services etc. I have put these solutions into a batch file to speed up this process.

The first batch file works for Server 2008 & 2008R2. Just copy the code, paste it into notepad and save it as a .bat file. If you have UAC enabled, right click the batch file and select Run As Administrator.


@echo off

Title Server 2008 WSUS Fix

echo.
echo Ensure you run this batch file with Administrator privledges.
echo.

:choice
echo 1. Run WSUS Fix
echo 2. Exit
echo.
set /p choice=Please choose a task:
echo.
set choice=%choice:~0,1%
if "%choice%"=="1" goto start
if "%choice%"=="2" goto exit
echo Invalid choice, please try again.
goto choice

:start
cls
echo.
gpupdate /target:computer /force
goto proxy

:proxy
cls
echo.
netsh winhttp reset proxy > nul
goto service_stop

:service_stop
cls
echo.
net stop wuauserv
goto service_start

:service_start
cls
echo.
net start wuauserv
goto check_for_updates

:check_for_updates
cls
wuauclt /detectnow /resetauthorization
goto wuapp

:wuapp
wuapp
goto exit

:exit:
exit



The second batch file works for Server 2003R2. Just copy the code, paste it into notepad and save it as a .bat file.


REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v SusClientId /f
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v SusClientIdValidation /f
net stop "Automatic Updates"
move %windir%\windowsupdate.log %windir%\windowsupdate.old.log
move %windir%\SoftwareDistribution %windir%\SoftwareDistributionold
regsvr32 /s atl.dll
regsvr32 /s wucltui.dll
regsvr32 /s wups.dll
regsvr32 /s wuaueng.dll
regsvr32 /s wuapi.dll
regsvr32 /s msxml3.dll
regsvr32 /s mssip32.dll
regsvr32 /s initpki.dll
regsvr32 /s softpub.dll
net start "Automatic Updates"
wuauclt /resetauthorization /detectnow
exit



Please note, in some cases the server will required a reboot to pull the updates down.

If you use VMWare and deploy a lot of virtual machines from templates then these batch files will come in very handy indeed.

Disclaimer: This script is provided as is without any warranty. You are responsible for running this script and I will not be held accountable for any data loss or issues arising from this script.

Add Comment

Batch Files   Windows Updates   WSUS   Windows Server   Scripts

Back to Technology