Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

Batch script for windows & software updates installation


  • Please log in to reply
39 replies to this topic

#1
centi50

centi50

    Newbie

  • Member
  • 37 posts
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

Edited by centi50, 03 May 2011 - 06:58 PM.



How to remove advertisement from MSFN

#2
myselfidem

myselfidem

    Member

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,559 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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

Edited by myselfidem, 07 May 2011 - 01:24 AM.

For Windows 7 OS: SetProductKey.rar (fr-FR/en-US. Integrate keys).

#3
centi50

centi50

    Newbie

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

#4
centi50

centi50

    Newbie

  • Member
  • 37 posts
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
myselfidem

myselfidem

    Member

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,559 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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

Edited by myselfidem, 07 May 2011 - 04:04 AM.

For Windows 7 OS: SetProductKey.rar (fr-FR/en-US. Integrate keys).

#6
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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
centi50

centi50

    Newbie

  • Member
  • 37 posts
Yzowl. What Folder are u talking Abt.

#8
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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
centi50

centi50

    Newbie

  • Member
  • 37 posts
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
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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
myselfidem

myselfidem

    Member

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,559 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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 ==
----------------------------------------------------------------------------------------------------------------

Edited by myselfidem, 07 May 2011 - 12:07 PM.

For Windows 7 OS: SetProductKey.rar (fr-FR/en-US. Integrate keys).

#12
centi50

centi50

    Newbie

  • Member
  • 37 posts
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
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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
centi50

centi50

    Newbie

  • Member
  • 37 posts
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
myselfidem

myselfidem

    Member

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,559 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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.
For Windows 7 OS: SetProductKey.rar (fr-FR/en-US. Integrate keys).

#16
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,038 posts
  • OS:none specified
  • Country: Country Flag
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

Edited by jaclaz, 08 May 2011 - 08:56 AM.


#17
myselfidem

myselfidem

    Member

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,559 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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 ==
------------------------------------------------------------

Edited by myselfidem, 08 May 2011 - 12:28 PM.

For Windows 7 OS: SetProductKey.rar (fr-FR/en-US. Integrate keys).

#18
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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
myselfidem

myselfidem

    Member

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,559 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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"

Edited by myselfidem, 08 May 2011 - 03:32 PM.

For Windows 7 OS: SetProductKey.rar (fr-FR/en-US. Integrate keys).

#20
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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"


#21
myselfidem

myselfidem

    Member

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,559 posts
  • OS:Windows 7 x64
  • Country: Country Flag
Many thanks Yzöwl
Really nice and awesome! :thumbup
But, I must admit it is hard for me, because I'm a newbe with batch files.
However It's very interresting to learn how that works.

Thanks again for your time and the very useful informations!

Edited by myselfidem, 08 May 2011 - 04:53 PM.

For Windows 7 OS: SetProductKey.rar (fr-FR/en-US. Integrate keys).

#22
centi50

centi50

    Newbie

  • Member
  • 37 posts
What if am to install Win Xp Updates, is there something to edit in the Batch code Being Provided here

#23
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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"


#24
centi50

centi50

    Newbie

  • Member
  • 37 posts
Thanks Yzöwl

Thanking Everyone for helping me out

PEACE AND LOVE TO ALL :thumbup

#25
centi50

centi50

    Newbie

  • Member
  • 37 posts
Please can anyone Modify this batch Script to include the Installation of software updates of the type SFXCAB.EXE as in Silverlight and type WEXTRACT.EXE as in Microsoft Visual C++ 2005 Redisributable package.

The above script will Search for the updates in The form of KB in the folder and subfolders is Placed in.

The scenario that i was faced with was after Manual downloading the windows updates which obviously were like

windowsxp-kb2476490-x86-enu_1545ba40647300fc0cde0c3e4c8e307e7d77d45d
ndp40-kb2518870-x86_42ed6547df9927704552b65505ed7dd76b363be6


and many others like the above two, i also included the software optional updates like type SFXCAB.EXE as in Silverlight and type WEXTRACT.EXE as in Microsoft Visual C++ 2005 Redisributable package. the above script did not install the software optional updates.

Therefore Please can Anyone modify the script to make it possible also to install software optional updates. That is if it is Possible.

your Help will be highly appreciated

Thanking All In Advance

Edited by Yzöwl, 23 June 2011 - 12:11 PM.
Merged New Topic with its directly related thread





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users



How to remove advertisement from MSFN