Jump to content

Batch script for windows & software updates installation


Recommended Posts

HOLEY KROWS!!!

Sorry to bump this but SILLY ME went nutz trying to figure out why files/paths weren't being found!

HERE is the reason - I had a "!" (exclamation point) as part of a Folder Name! DO NOT DO THIS since

SET ENABLEDELAYEDEXPANSION

specifically EXPECTS to use that as a Variable Delimiter, same case as CMD.EXE "/V:ON".

Do NOT use that anywhere in any Pathname/Filename. (wasted time via experimentation...)

HTH some poor idee-yut that does the same thing. :(

Edited by submix8c
Link to comment
Share on other sites

  • 4 weeks later...

For windows xp updates, you can probably get away with simply changing MSU to EXE and removing WUSA.

@ECHO OFF 
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /R "%~dp0" %%A IN (*-KB*.EXE) DO (
CALL :SUB %%~nA
ECHO= Installing KB!KB_NUM!
>NUL PING -n 4 127.0.0.1
"%%A" /quiet /norestart)
ECHO= == Press any key to restart ==
>NUL PAUSE
SHUTDOWN.EXE /r /t 0
GOTO :EOF

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

Dear sir,

Is it possible to include a string to output the installed KB numbers into a text file within the directory? Pardon my newbie question as I am a newbie in scripting :(

Edited by gohnick
Link to comment
Share on other sites

I won't swear to this, but putting

ECHO= == List of KB's installed == >KBLIST.TXT

right after the "SETLOCAL" and then placing

        ECHO= Installing KB!KB_NUM! >>KBLIST.TXT 

after the other one should do it. :unsure:

Link to comment
Share on other sites

I won't swear to this, but putting

ECHO= == List of KB's installed == >KBLIST.TXT

right after the "SETLOCAL" and then placing

        ECHO= Installing KB!KB_NUM! >>KBLIST.TXT 

after the other one should do it. :unsure:

Hi submix8c,

Thanks for the tip! it works! :)

Link to comment
Share on other sites

  • 1 month later...

Hello to All

I use the following code Batch script to Install the updates in a folder in my Win 7 x64 laptop.

@ECHO OFF
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
SHUTDOWN.EXE /r /t 0
GOTO :EOF

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

The above code will Install all updates of .MSU located in a folder same as the batch script one after the other. What it won't do is, it won't install updates of .EXE e.g .NetFramework 4 updates and also it won't install Silverlight Updates.

Please can some one Kindly re edit the above script for me to include the installation of .EXE files and Silverlight updates.

Also note am totally zero in scripting, so kindly if changes are made please reproduce the above script with changes so i can copy and paste it in my .BAT file.

Also note the code is not mine. i just got it in this thread, as i am the thread starter.

Thanking all in advance for their time and efforts to Help out people like me.

Link to comment
Share on other sites

  • 7 months later...

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

PUSHD %~dp0

FOR %%A 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 restart ==

>NUL PAUSE

SHUTDOWN.EXE /r /t 0

GOTO :EOF

:SUB

SET "KB_NUM=%*"

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

So this is the script I should use? What about the exe files?

Link to comment
Share on other sites

@ECHO OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONPUSHD %~dp0FOR %%A IN (*-KB*.MSU) DO (<SNIP />
So this is the script I should use? What about the exe files?

If you'd looked a little harder you'd have also noticed an example script for .EXE files too!

All that was needed was to join them into one, perhaps something like this UnTested:

Example for recursion:

@ECHO OFFSETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSIONFOR /R "%~dp0" %%A IN (*-KB*.*) DO (	IF /I %%~xA==.MSU (SET _=WUSA) ELSE (		IF /I NOT %%~xA==.EXE GOTO :EOF		SET "_=")	CALL :SUB "%%~nA"	>NUL TIMEOUT /t 3	%_% "%%A" /quiet /norestart)ECHO= == Press any key to restart ==>NUL PAUSESHUTDOWN /rGOTO :EOF:SUB	SET "KB_NUM=%*"	FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO (		ECHO= Installing KB%%B)

Example for all in same directory:

@ECHO OFFSETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSIONPUSHD %~dp0FOR %%A IN (*-KB*.*) DO (	IF /I %%~xA==.MSU (SET _=WUSA) ELSE (		IF /I NOT %%~xA==.EXE GOTO :EOF		SET "_=")	CALL :SUB %%~nA	>NUL TIMEOUT /t 3	%_% "%%~fA" /quiet /norestart)ECHO= == Press any key to restart ==>NUL PAUSESHUTDOWN /rGOTO :EOF:SUB	SET "KB_NUM=%*"	FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO (		ECHO= Installing KB%%B)
Link to comment
Share on other sites

I use this in my 8.1 ua install (batch script is run outside of the Updates\msu directory and should wk with 7 as well), does a update count then log file when done..Happy Holidays

DP :thumbup

@echo off&setlocal ENABLEDELAYEDEXPANSION&color 1f&&title, [ WUSA - 8.1 UPDATE INSTALLER ]pushD "%~dp0" & cd /d "%~dp0":: ### SCAN FOR UPDATES ----------------------------------------------------------for /F %%a in ('dir Updates\msu\*.msu ^|findstr /i "file(s)"') do set z=%%a        echo Number Of Updates Found: %z%echo:&echo::: ### INSTALLING UPDATES (reads updates in numerical order)---------------------        echo == Installing %z% Windows Updates..(This may take a while, Please Wait)echo:for /R "%~dp0" %%A IN (*.MSU) DO (        SET /A COUNT+=1        ECHO= Installing !COUNT! of %z% = %%~nA        >NUL TIMEOUT /t 3        start /wait WUSA "%%A" /quiet /norestart)popDendlocalgoto :wpi:wpi:: ### DATED UPDATE LOG FILE WHEN DONE-------------------------------------------set wusa=%systemdrive%\HotFixes-%date:~10,4%-%date:~4,2%-%date:~7,2%-%date:~0,3%.htmwmic qfe list full /format:htable>%wusa%
Edited by DosProbie
Link to comment
Share on other sites

  • 1 month later...
  • 8 months later...

Guys Im lost here.

 

I need a script to install all msu files on a folder but I need this script to "ignore" an update if its already installed on the system. Is that the normal behavior of these scripts? If not, how can I make this script do the ignore installed thing?

 

script in use is this:

 

@echo off
TITLE INSTALADOR DE ATUALIZACOES DO WINDOWS
CLS
setlocal ENABLEDELAYEDEXPANSION
pushd "%~dp0"
echo:
echo PREPARANDO ATUALIZACOES..
echo:
for /F %%a in ('dir *.msu ^| find /i "file(s)"') do set z=%%a
if "%z%"=="" goto :Failure
echo Atualizacoes encontradas: %z%
echo:
echo Instalando atualizacoes... (Esta tarefa pode demorar)
echo:
FOR /R "%~dp0" %%A IN (*.MSU) DO (
        SET /A COUNT+=1
        ECHO= Instalando !COUNT! de %z% = %%~nA
        >NUL TIMEOUT /t 3
        WUSA "%%A" /quiet /norestart
)
echo Instaladas %z% atualizacoes dia %date% as %time%.
echo:
echo Reinicie o seu computador!
CHOICE /C YN /N /M "Reiniciar agora? [Y]es [N]o :"
if %errorlevel%==1 goto :Reboot
if %errorlevel%==2 goto :Exit
:Failure
CLS
echo ==========================================================
echo:
echo    NENHUMA ATUALIZACAO ENCONTRADA
echo:
echo    ATENCAO: As atualizacoes precisam estar na mesma pasta onde este script se encontra.
echo:
echo ==========================================================
echo:
pause
goto :Exit
:Reboot
ENDLOCAL
start shutdown.exe /r /t 0   
:Exit
ENDLOCAL
exit

 

Link to comment
Share on other sites

I don' tget it.

Where does that script come from?

Have you written it?

What does it does? (I mean does it actually, even minimally, work?)

 

If you set a variable inside a FOR loop, it's "%" value won't be altered, you need to use the expanded "!" value.

 

Example:

@ECHO OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET Variable=A suffusion of yellowFOR /L %%A IN (1,1,10) DO (SET Variable=%%AECHO %Variable%ECHO !Variable!)

jaclaz

Link to comment
Share on other sites

sorry jaclass. that was just a concept that I found (i guess in this forum). I have a fully functional script here but unfortunately its not worth. The script takes too long to install all the msus i have. Now im trying to figureout how to make ntlites nuyhi tool to work with the updates and some removals :P

 

thanks anyway...

 

sorry about my bad english.. :P

Link to comment
Share on other sites

yro,

 

The update files have a KB number in the filenames and systeminfo gives KB numbers installed so I looked at how the data could be used to set which filename to allow to be installed.

 

This is a test script I came up with.

@echo offsetlocal enabledelayedexpansion:: Set a counter for the KB[i] series of variablesset i=0:: Find installed KB numbers from systeminfo and add to KB[i] variablesfor /f "tokens=2" %%A in ('systeminfo^|findstr /i "\<KB[0-9][0-9]*$"') do (	set /a i += 1	set KB[!i!]=%%A):: Set ubound to 1st KB variableset KB[0]=%i%:: Loop through recursive search for msu files:: In each filename, find KB number, if not found then install filename:: Remove the echo in front of wusa used in testing to execute the wusa:: command and remove the pause linefor /R "%~dp0" %%U in (*.msu) do (	set /a count += 1	set installed=0	echo Instalando !count! de %z% = %%~nU	timeout /t 3 > nul	for /l %%I in (1, 1, %KB[0]%) do (		echo %%~nU| find /i "!KB[%%I]!"> nul		@if not errorlevel 1 set installed=1	)	@if !installed! equ 0 echo wusa "%%U" /quiet /norestart)endlocalpausegoto :eof

It puts each KB string into a variable KB where i is a numbered index (like how an array on access works). That makes the data easier to loop through many times over.

 

If the KB string is found in the filename, then installed is set to 1 so installation will not happen.

 

Edit: Added /i to find and findstr so case sensitivity would not be an issue.

Edited by MHz
Link to comment
Share on other sites

  • 4 months later...

I changed the code to echo/push the update name into a text file. 

I really don't need/want to attempt all updates at one time. It needs to install in 2-3 updates.

Can we use this text files at check if the update has already been installed?

Currently I stop about 40-50% complete and reboot then start again, but it attempts to install from the very beginning.

 

I tried to edit these scripts, but I'm not able to.

any thoughts?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...