Batch – Manage Windows Updates by Script

email me

Manage Windows Update via a script.

@echo off

set sysPath=C:\Windows\system32

:: STOP SERVICE
%sysPath%\net stop wuauserv

:: REMOVE KEYS
%sysPath%\reg DELETE “HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update” /v “LastWaitTimeout” /reg:64 /f

%sysPath%\reg DELETE “HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update” /v “DetectionStartTime” /reg:64 /f


%sysPath%\reg DELETE “HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update” /v “NextDetectionTime” /reg:64 /f

:: ADD REG KEYS

:: AUTO UPDATE IS ENABLED
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “NoAutoUpdate” /t REG_DWORD /d “0” /reg:64 /f

:: DOWNLOAD AND INSTALL
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “AUOptions” /t REG_DWORD /d “3” /reg:64 /f

:: 0 IS SET TO EVERY DAY
:: but we could schedule time and day
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “ScheduledInstallDay” /t REG_DWORD /d “0” /reg:64 /f

:: ADD 2400 TIME HERE BY HOUR

%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “ScheduledInstallTime” /t REG_DWORD /d “19” /reg:64 /f

:: USE AUTO REBOOT WHILE LOGGED IN
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “NoAutoRebootWithLoggedOnUsers” /t REG_DWORD /d “0” /reg:64 /f

:: YES INSTALL MINOR UPDATES
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “AutoInstallMinorUpdates” /t REG_DWORD /d “1” /reg:64 /f

:: PROMPT FOR REBOOT IS ENABLED AND SET FOR 60 MINUTES – WARN USER EVERY HOUR
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “RebootRelaunchTimeoutEnabled” /t REG_DWORD /d “00000001” /reg:64 /f
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “RebootRelaunchTimeout” /t REG_DWORD /d “60” /reg:64 /f

:: FOR A SCHEDULED INSTALL, RETRY A MISSED INSTALL EVERY 15 MINUTES 
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “RescheduleWaitTimeEnabled” /t REG_DWORD /d “00000001” /reg:64 /f
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “RescheduleWaitTime” /t REG_DWORD /d “15” /reg:64 /f

:: CHECK FOR UPDATES EVERY 22 HOURS – WHICH IS THE DEFAULT IF ENABLED
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “DetectionFrequencyEnabled” /t REG_DWORD /d “1” /reg:64 /f

:: FOR A SCHEDULED REBOOT, IT IS ENABLED AND SET FOR 8 HOURS TO WAIT BEFORE PROCEEDING WITH A SCHEDULED RESTART
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “RebootWarningTimeoutEnabled” /t REG_DWORD /d “1” /reg:64 /f
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “RebootWarningTimeout” /t REG_DWORD /d “480” /reg:64 /f

:: USE WSUS IS DISABLED
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “UseWUServer” /t REG_DWORD /d “0” /reg:64 /f

:: ALLOW SHUTDOWN IS ENABLED
%sysPath%\reg ADD “HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU” /v “NoAUShutdownOption” /t REG_DWORD /d “0” /reg:64 /f

:: REGISTER COMPONENTS
%sysPath%\regsvr32 wuaueng.dll /s
%sysPath%\regsvr32 wuauserv.dll /s
%sysPath%\regsvr32 wucltui.dll /s
%sysPath%\regsvr32 wups.dll /s
%sysPath%\regsvr32 wuweb.dll /s
%sysPath%\regsvr32 iuengine.dll /s

%sysPath%\wuauclt /resetauthorization /detectnow

:: START SERVICE
%sysPath%\net start wuauserv

%sysPath%\wuauclt /ReportNow /DetectNow
:: %sysPath%\wuauclt /UpdateNow

:: not used
::%sysPath%\wuauclt /ShowWU

::NOTES

::NoAutoUpdate: Reg_DWORD
:: 0: Automatic Updates is enabled
:: 1: Automatic Updates is disabled

:: AUOptions: Reg_DWORD
:: 1: Keep my computer up to date has been disabled in Automatic Updates
:: 2: Notify of download and installation
:: 3: Automatically download and notify of installation
:: 4: Automatically download and scheduled installation

:: ScheduledInstallDay: Reg_DWORD
:: 0: Every day
:: 1 through 7: The days of the week from Sunday (1) to Saturday (7)

:: ScheduledInstallTime: Reg_DWORD
:: n equals the time of day in a 24-hour format (0-23).

:: UseWUServer: Reg_DWORD
:: 0 = disabled
:: 1 = enable, to configure a WSUS

:: RescheduleWaitTime: Reg_DWORD
:: 1-60 minutes wait time

:: NoAutoRebootWithLoggedOnUsers: Reg_DWORD
:: 0 = true
:: 1 = false

:: AutoInstallMinorUpdates: Reg_DWORD
:: 0 = false
:: 1 = true