MSFN Forum: Batch script for windows & software updates installation - MSFN Forum

Jump to content


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Batch script for windows & software updates installation Installation of windows Updates incl software Updates via Batch script

#1 User is offline   centi50 

  • Newbie
  • Group: Members
  • Posts: 37
  • Joined: 25-January 10

Posted 03 May 2011 - 06:52 PM

Hello to all,

Am no Computer guru nor Programmer Geek. Please please can anyone write me a batch script for installing win 7 updates manually from a folder i have on hard disk.This is what i want to be exact.

I have windows updates files i have been downloading from catalog.update.microsoft.com. in a folder on Drive D of my Laptop. now every time there is an update alert by windows 7 update agent, i go to catalog.update.microsoft.com and download the updates to my folder. This way i dont have to download the same updates when i want to update my PC desktop running widows 7.

So i humbly ask this great community to help me out to accomplish this by giving me a batch script which i can paste on Notepad and save it as a .bat file so when i double click my .bat file i will install my updates silently on the target system.

eg. AMD64-all-windows6.1-kb2482017-x64_95006a2b965e8566d8a57600a0c0c53cb7212874.msu
AMD64-all-windows6.1-kb2479628-x64_a774713ef62d45373a08d4a7c0acfa18e8ec87c8.msu

I want a batch script to find the msu's file in a folder and install them silently. It should install the the first update till finnish before installing the second one and so forth.


This is what i've been doing.

1. open cmd prompt and i type "DIR *.* /B >My folder name.bat (eg i have a folder for Apr 2011 updates named 12 Apr 11 Updates win 7) so i type "DIR *.* /B >12apr11upadteswin7.BAT" at the cmd prompt. This will give me all the file names of the msu's in a text file.

2. Then i manually replace .msu with .msu /quiet /norestart Eg. AMD64-all-windows6.1-kb2482017-x64_95006a2b965e8566d8a57600a0c0c53cb7212874.msu changes to AMD64-all-windows6.1-kb2482017-x64_95006a2b965e8566d8a57600a0c0c53cb7212874.msu /quiet /norestart
. i do this for all the msu files in that folder.

3. Then i add
@echo off
echo Installing 12 Apr 2011 Updates...... to be the first and second line of my batch file named 12apr11upadteswin7.BAT. so i have something like this at the end

@echo off
echo Installing 12 Apr 2011 Updates......
AMD64-all-windows6.1-kb2393802-x64_98de62e1afe597d60acb584552241477315bd33a.msu /quiet /norestart
AMD64-all-windows6.1-kb2425227-x64_0749e0e8531479e1de9347fe584e61d43c209c0f.msu /quiet /norestart
AMD64-all-windows6.1-kb2454826-v2-x64_1c0a9c5f9fa8a2ffebfc81c3163a46caf077838a.msu /quiet /norestart
AMD64-all-windows6.1-kb2467023-x64_7f10b8f14a55877cf2ee67cee41ab758c3a9b376.msu /quiet /norestart
AMD64-all-windows6.1-kb2475792-x64_2e8f675625883458482042e128f54167f0193f9b.msu /quiet /norestart
AMD64-all-windows6.1-kb2479628-x64_a774713ef62d45373a08d4a7c0acfa18e8ec87c8.msu /quiet /norestart
AMD64-all-windows6.1-kb2485376-x64_7082a10a94b6cfffdd28f5f57f02e15a5345f5a7.msu /quiet /norestart
AMD64-all-windows6.1-kb2487426-x64_248e8f34492d9ed52236150179313aaf29a544d4.msu /quiet /norestart
AMD64-all-windows6.1-kb2482017-x64_95006a2b965e8566d8a57600a0c0c53cb7212874.msu /quiet /norestart



Now i dont want to be finding .msu and replacing with .msu /quiet /norestart manually.

I want a script that will search my folder may be i have subfolders to seach in that too for msu's and install them one by one waiting to finnish installing the first update before installing the second one. i hope i have tried to explain myself clear




Your efforts to help this humble soul of mine will be highly appreciated

This post has been edited by centi50: 03 May 2011 - 06:58 PM



#2 User is offline   myselfidem 

  • Member
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,447
  • Joined: 06-January 10
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 04 May 2011 - 12:22 AM

I found this batch file, but I don't remember where. Tested and working!
But I don't know how to add timeout /t 3 (waiting after each update installed!)
Set the batch file inside the folder where you have all the updates you want install and launch the batch.

Updates.cmd
@echo off
for /f "skip=1" %%A in ('dir /b *.msu') do (
echo Installing Updates "%%A" ...
start /wait %%A /quiet /norestart > nul
)
echo.
echo ###########################################################
echo.
echo Updates installed
echo Press any key to restart
pause >NUL
shutdown -r -t 0



*Edit: the value "skip=1" is wrong and the first update will not be installed like explained by Yzöwl

This post has been edited by myselfidem: 07 May 2011 - 01:24 AM


#3 User is offline   centi50 

  • Newbie
  • Group: Members
  • Posts: 37
  • Joined: 25-January 10

Posted 04 May 2011 - 07:04 AM

Thanks myselfidem for your time and efforts to help me out. i'll try ur batch script

#4 User is offline   centi50 

  • Newbie
  • Group: Members
  • Posts: 37
  • Joined: 25-January 10

Posted 04 May 2011 - 11:32 AM

Thanks myselfidem the scrripts works fine.
But i would like to include wusa.exe in the batch script to install the updates can anyone help please.

#5 User is offline   myselfidem 

  • Member
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,447
  • Joined: 06-January 10
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 04 May 2011 - 01:00 PM

I've made some changes inside the batch file and works also fine like this for me, using wusa.exe:

@echo off
for /f %%A in ('dir /b *.msu') do (
echo == Installing Updates == "%%A" ...
timeout /t 3
C:\Windows\system32\wusa.exe %%A /quiet /norestart
)
echo.
echo ###########################################################
echo.
echo == Updates installed ==
echo.
echo == Press any key to restart ==&pause>nul
echo.
shutdown.exe /r /t 0



*Edit: post updated! Removed "skip=1" inside the batch file like explained by Yzöwl

This post has been edited by myselfidem: 07 May 2011 - 04:04 AM


#6 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 05 May 2011 - 01:16 PM

I've seen this code here before, and never really got round to mentioning it, why are you not installing all of the .msu files in that directory?

#7 User is offline   centi50 

  • Newbie
  • Group: Members
  • Posts: 37
  • Joined: 25-January 10

Posted 05 May 2011 - 08:06 PM

Yzowl. What Folder are u talking Abt.

#8 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 05 May 2011 - 11:55 PM

When your code does a directory listing of *.msu files, the first result, alphabetically by default, is deliberately being ignored and therefore not processed, (skip=1).

Additional note, please use correct English, not text speak, it helps our non English speakers to follow the conversations better.

#9 User is offline   centi50 

  • Newbie
  • Group: Members
  • Posts: 37
  • Joined: 25-January 10

Posted 06 May 2011 - 06:17 PM

Yzowl. I dont know anything about batch programming. what i wanted was a batch file that can search my folders for .msu files and install them silently. Thanx to myselfidem he provided me the Batch code and it installed my msu's file. If you have a better Code. i'll be happy to employ it.

#10 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 06 May 2011 - 11:34 PM

That batch file you were provided with could not have installed all of your .msu files in that folder, silently or otherwise!

It skipped the first .msu file, because the code is wrong.

I've already told you why it skipped the first file, so just remove that request from the code and it will be instantly better.

#11 User is offline   myselfidem 

  • Member
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,447
  • Joined: 06-January 10
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 07 May 2011 - 01:00 AM

Many thanks Yzöwl
You're right. I haven't seen this before!
I've updated my last posts!
However, with this changes all updates .msu will be installed with the batch file inside the folder where are located all the updates, like you said.
(Removed "skip=1")

@echo off
for /f %%A in ('dir /b *.msu') do (
echo == Installing Updates == "%%A" ...
timeout /t 3
C:\Windows\system32\wusa.exe %%A /quiet /norestart
)
echo.
echo ########################################
echo.
echo == Updates installed ==
echo.
echo == Press any key to restart ==&pause>nul
echo.
shutdown.exe /r /t 0




For Windows 7 French localised version

@echo off
for /f %%A in ('dir /b *.msu') do (
echo == Installation des Mises … jour == "%%A" ...
timeout /t 3
C:\Windows\system32\wusa.exe %%A /quiet /norestart
)
echo.
echo ########################################
echo.
echo == Mises … jour install‚es ==
echo.
echo == Appuyez sur n'importe qu'elle touche pour red‚marrer ==&pause>nul
echo.
shutdown.exe /r /t 0



@centi50
Sorry, I haven't seen this error before!

*Edit: Output inside the command window
timeout /t 3 (means waiting 3 seconds between each update to install)

----------------------------------------------------------------------------------------------------------------
== Installation des Mises à jour == "Windows6.1-KB2425227-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2479943-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2491683-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2503658-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2506212-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2506223-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2507618-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2508272-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2508429-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2509553-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...
== Installation des Mises à jour == "Windows6.1-KB2511455-x86.msu" ...

Attendre 0 secondes, appuyez sur une touche pour continuer...

#######################################################

== Mises à jour installées ==

== Appuyez sur n'importe qu'elle touche pour redémarrer ==
----------------------------------------------------------------------------------------------------------------

This post has been edited by myselfidem: 07 May 2011 - 12:07 PM


#12 User is offline   centi50 

  • Newbie
  • Group: Members
  • Posts: 37
  • Joined: 25-January 10

Posted 07 May 2011 - 07:29 AM

Big Up to mselfidem and Yzöwl for Helping out. As i said am no Computer Geek or Guru, so there was no way i was going to spot any error in any batch code. But thanks to Bro Yzöwl . And Thx to myselfidem. To help me. Two questions i have to my friends.

1.I see the start & wait cmd is not there. will the installation still wait for the first installation to finnish then go to the other one. or will it start the second installation even if the first did not finnish?

2. Will these script search into subfolders containing the .MSU files? if not, Can anyone modify the batch to make it search into subfolder and install the .MSU files.

Please if somebody will modify the batch code and post, i kindly ask him or her to post the full batch code and not only the modification, Becoz i will not understand. i'll just copy the batch and save it.

Once again i thank all who helped me.

#13 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 07 May 2011 - 12:17 PM

Since we have a member already providing you with scripted help, the following script is posted only as an example.
@ECHO OFF&SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /R %%# IN (*-KB*.MSU) DO (CALL :SUB %%~n#
	ECHO= INSTALLING KB!_!&ECHO=WUSA "%%#" /QUIET /NORESTART)
PAUSE&GOTO :EOF
:SUB
SET "_=%*"
FOR /F "DELIMS=-" %%$ IN ("%_:*-KB=%") DO SET "_=%%$"
It does answer your second question but may not perform to your exact requirements.

#14 User is offline   centi50 

  • Newbie
  • Group: Members
  • Posts: 37
  • Joined: 25-January 10

Posted 08 May 2011 - 08:09 AM

Thanks Yzöwl,

Please can you or anyone Explain to me or what does this line mean FOR /R %%# IN (*-KB*.MSU) DO (CALL :SUB %%~n#

Thanking everyone in Advance

#15 User is offline   myselfidem 

  • Member
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,447
  • Joined: 06-January 10
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 08 May 2011 - 08:37 AM

You can find help using:

Start | Run and write: cmd

Inside the command window, write (examples):

for /? >C:\for.txt

call /? >C:\call.txt

After you can read the help about this commands inside the text files.

#16 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 08 May 2011 - 08:55 AM

A better source is actual dedicated sites:
http://ss64.com/nt/
http://www.robvander.../batchfiles.php

Yzöwl, which is our resident "batch master" :thumbup has a "quirk" to writing very good snippets/scripts in the most simplified (which sometimes means complex ) way :ph34r: ).

This:
@ECHO OFF&SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION 
FOR /R %%# IN (*-KB*.MSU) DO (CALL :SUB %%~n# 
        ECHO= INSTALLING KB!_!&ECHO=WUSA "%%#" /QUIET /NORESTART) 
PAUSE&GOTO :EOF 
:SUB 
SET "_=%*" 
FOR /F "DELIMS=-" %%$ IN ("%_:*-KB=%") DO SET "_=%%$"


Can be re-written as:
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS 
SETLOCAL ENABLEDELAYEDEXPANSION 
FOR /R %%A IN (*-KB*.MSU) DO (
CALL :SUB %%~nA
ECHO INSTALLING KB!KB_number!
ECHO=WUSA "%%A" /QUIET /NORESTART
) 
PAUSE

GOTO :EOF 

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


Which may be more readable. :unsure:

jaclaz

This post has been edited by jaclaz: 08 May 2011 - 08:56 AM


#17 User is offline   myselfidem 

  • Member
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,447
  • Joined: 06-January 10
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 08 May 2011 - 12:00 PM

Thanks Yzöwl and jaclaz! :thumbup

I've made some changes and the batch file works fine for me like below!

After testing I see this batch file works fine, if I set the batch file inside a folder (example: C:\Post_SP1\) and the batch searching inside a subfolder (example: C:\Post_SP1\Updates);
or if it is inside the same folder where the updates are located (example: C:\Post_SP1\Updates\).

The batch file is inside C:\Post_SP1\ or inside C:\Post_SP1\Updates and is working fine (outside or inside the folder).
Works also fine if I launch the batch file on C:\ partition!

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS 
SETLOCAL ENABLEDELAYEDEXPANSION 
FOR /R %%A IN (*-KB*.MSU) DO (
CALL :SUB %%~nA
ECHO INSTALLING KB!KB_number!
TIMEOUT /t 3 >NUL 
C:\Windows\System32\wusa.exe %%A /quiet /norestart
) 
ECHO == Press any key to restart ==&PAUSE>NUL
shutdown.exe /r /t 0
GOTO :EOF 

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




Output command window

------------------------------------------------------------
INSTALLING KB2425227
INSTALLING KB2479943
INSTALLING KB2491683
INSTALLING KB2503658
INSTALLING KB2506212
INSTALLING KB2506223
INSTALLING KB2507618
INSTALLING KB2508272
INSTALLING KB2508429
INSTALLING KB2509553
INSTALLING KB2511455
== Press any key to restart ==
------------------------------------------------------------

This post has been edited by myselfidem: 08 May 2011 - 12:28 PM


#18 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 08 May 2011 - 01:16 PM

Just thought I'd add a note about the use of the /R switch with FOR in this case.

You are recursing the directory rooted at the current directory, not necessarily that of the batch files location. If you wanted to make sure of that I'd suggest that you think about using either:
FOR /R C:\Post_SP1 %%A IN (
or
FOR /R %~dp0 %%A IN (
You may of course need to ensure that paths with spaces are catered for too!

#19 User is offline   myselfidem 

  • Member
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,447
  • Joined: 06-January 10
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 08 May 2011 - 03:23 PM

Thanks Yzöwl to point me about this question!
Could you tell me if the batch file is correct like this.

Works for me, even if the folder has a space in its name.

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS 
SETLOCAL ENABLEDELAYEDEXPANSION 
FOR /R "%~dp0" %%A IN (*-KB*.MSU) DO (CALL :SUB %%~nA
ECHO INSTALLING KB!KB_number!
TIMEOUT /t 3 >NUL 
C:\Windows\System32\wusa "%%A" /quiet /norestart) 
ECHO == Press any key to restart ==&PAUSE>NUL
shutdown.exe /r /t 0
GOTO :EOF 

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


This post has been edited by myselfidem: 08 May 2011 - 03:32 PM


#20 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 08 May 2011 - 04:27 PM

That is correct.

Do bear in mind that WUSA.EXE is located within %PATH% as is SHUTDOWN.EXE and that executables located within the path do not require their path prepending to the command. You have done so with one and not the other, whilst both are correct it seems pointless to include that which isn't required.
You can also simplify lines 2 & 3 by merging them into one thus
@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"


Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy