Link to home
Start Free TrialLog in
Avatar of Sean Plemons Kelly, CISSP
Sean Plemons Kelly, CISSPFlag for United States of America

asked on

Windows updates batch files

Hello fellow experts!

Running into an issue with a batch file we have, with the purpose to install windows updates offline.

@ECHO OFF&COLOR E && CLS && MODE 60,20&TITLE  [ MULTI UPDATE INSTALLER ]

ECHO. Installing Windows Updates... Please Wait!

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
PUSHD %~dp0
FOR %AA IN (*-KB*.MSU) DO (
	CALL :SUB %%~nA
	ECHO= Installing KB!KB_NUM!
	>NUL TIMEOUT /t 3
	WUSA "%%~fA" /quiet /norestart)
ECHO= == Press any key to quit ==
>NUM PAUSE
REM SHUTDOWN.exe /r /t 0
PAUSEENDLOCALGOTO :EOF

:SUB
SET "KB_NUM=%*"
FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO SET "KB_NUM=%%B"

Open in new window


The above works great, but ONLY if it is run in a local folder, and from that folder.

Our issue, is that the server that we are running it on, has an OS partition, and is tossing errors based on the SETLOCAL part of it.

What I'm trying to (eventually) accomplish, is being able to deploy this as a script (or called from a .VBS) on our clients and member servers to install updates directly from the server, as well as allowing the host server to execute the batch file and install updates to itself from a separate partition.

Due to the nature of our setup, this MUST be accomplished via batch scripting or VBS. Third party software, and WSUS are not options here.

Cheers!
Avatar of zalazar
zalazar

The above code was not working well for me. You could try:
@ECHO OFF&COLOR E && CLS && MODE 60,20&TITLE  [ MULTI UPDATE INSTALLER ]
ECHO. Installing Windows Updates... Please Wait!
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /R "%~dp0" %%A IN (*-KB*.MSU) DO (
  CALL :SUB %%~nA
  ECHO= Installing KB!KB_NUM!
  >NUL TIMEOUT /t 3
  WUSA "%%A" /quiet /norestart)
ECHO= == Press any key to restart ==
>NUL PAUSE
REM SHUTDOWN.EXE /r /t 0
GOTO :EOF

:SUB
SET "KB_NUM=%*"
FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO SET "KB_NUM=%%B"

Open in new window


But I actually prefer to use a vbs script:
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
strScriptDir = Mid(Wscript.ScriptFullName, 1, InstrRev(Wscript.ScriptFullName, "\") - 1)
Wscript.Echo "Installing Windows Updates... Please Wait!"
Set f = fso.GetFolder(strScriptDir)
For Each f1 in f.Files
  If LCase(fso.GetExtensionName(f1.Name)) = "msu" Then
    Wscript.Echo " Installing " & f1.Name
    valRet = WshShell.Run("cmd.exe /c wusa.exe " & Chr(34) & f1.Name & Chr(34) & " /quiet /norestart", 7, true)
    Wscript.Sleep 3000
  End If
Next

Open in new window

I do see one problem the following line is wrong:

FOR %AA IN (*-KB*.MSU) DO (

Open in new window

and would need to be:

FOR %%A IN (*-KB*.MSU) DO (

Open in new window

~bp
Avatar of Sean Plemons Kelly, CISSP

ASKER

@Bill Prew- That was actually a typo on my part, the script is %%A. Sorry!

@zalazar- Just to verify, that is going to just run through all the update files in a network folder location, and install them locally? Also, I'm not as familiar with VBS, how would that handle errors (I.E. incorrect OS patch, patch already installed ,etc)?
So, if you don't want it to look for the files in the folder where the script exists, what folder do you want it to look for the files in?

~bp
Current setup looks something like this:
Server-
OS Partition
Everything else partition, split into shares (For patches, we'll call it \\SERVER\Patches\)

Ideally, everything would be pulling the patches from that share. We can't use WSUS, so this (for now) is going to have to be our patch management "solution".
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Script worked like a charm! Thanks for the help!