Jump to content
MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. ×

Sripted install Windows 7 Updates


 Share

Recommended Posts

I am currently struggling to find information on how

to install Windows 7 Update *.cab files.

In the past I used the below pasted simple script to

install Windows XP \ 2003 Hotfix collections that were

not yet integrated in the base-image.

Can anyone enlighten me with a working solution ?


dir "\\windows_xp\updates\windowsxp_x86\*" /b > %temp%\windowsxp_x86_glb.log
for /f "tokens=*" %%a in (%temp%\windows7_x64_glb.log) do "\\windows_xp\updates\windowsxp_x86\%%a" /quiet /norestart

Link to comment
Share on other sites


Pulls missing updates from Microsoft (or WSUS if configured for it) and installs:

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

WScript.Echo "Searching for updates..." & vbCRLF

Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software'")

WScript.Echo "List of applicable items on the machine:"

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
WScript.Echo I + 1 & "> " & update.Title
Next

If searchResult.Updates.Count = 0 Then
WScript.Echo "There are no applicable updates."
WScript.Quit
End If

WScript.Echo vbCRLF & "Creating collection of updates to download:"

Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
WScript.Echo I + 1 & "> adding: " & update.Title
updatesToDownload.Add(update)
Next

WScript.Echo vbCRLF & "Downloading updates..."

Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()

WScript.Echo vbCRLF & "List of downloaded updates:"

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded Then
WScript.Echo I + 1 & "> " & update.Title
End If
Next

Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

WScript.Echo vbCRLF & _
"Creating collection of downloaded updates to install:"

For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
WScript.Echo I + 1 & "> adding: " & update.Title
updatesToInstall.Add(update)
End If
Next

WScript.Echo "Installing updates..."
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()

'Output results of install
WScript.Echo "Installation Result: " & _
installationResult.ResultCode
WScript.Echo "Reboot Required: " & _
installationResult.RebootRequired & vbCRLF
WScript.Echo "Listing of updates installed " & _
"and individual installation results:"

For I = 0 to updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & _
updatesToInstall.Item(i).Title & _
": " & installationResult.GetUpdateResult(i).ResultCode
Next

Link to comment
Share on other sites

Thank you for the provided solutions.

However:

In my environment I want to control which updates are installed without making use of WSUS.

Slipstreaming into the image is fine, but does not help me to maintain running machines.

I am looking for information on how to install a set of tested windows 2008 updates.

In the past that was easy -> see script bit.

Although the script of IcemanND is very cool, it is not 100% what I need.

I assume I only need to know what kind of switches I can use to silently install windows 2008 *.cab files.

( or whatever method I can use ).

Link to comment
Share on other sites

Put your list of approved updates in an array or dictionary object, then modify the following section to see if the needed update is in array or dictionary object. If it is let it be added to the updatesToDownload object, if it is not then skip it. Only need to maintain a list of updates then don't have to download and maintain a folder somewhere full of updates to install.

Or you could do the inverse and only have a list of updates you do not want installed.

WScript.Echo vbCRLF & "Creating collection of updates to download:"
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
WScript.Echo I + 1 & "> adding: " & update.Title
updatesToDownload.Add(update)
Next

Link to comment
Share on other sites

Thx for the clever update IcemanND...I never thought of that option.

( I assume I am still too much focused on the very simple *.cmd approach ).

I like the part where we do not have to maintain an install-repository.

Saves me some space;)

Will let you know how this works out.

Edited by VATERNL
Link to comment
Share on other sites

Place a text file in the same folder as the script, the text file should only contain the numberical portion of the KB article number, one number per line.

WARNING: Untested


Const ForReading = 1

Set objSearcher = CreateObject("Microsoft.Update.Searcher")
Set DeniedUpdates = CreateObject("Scripting.Dictionary")
set objFSO = CreateObject("Scripting.FileSystemObject")

DeniedUpdates.CompareMode = VBBinaryCompare

Wscript.echo "Getting list of approved updates..." & VBCRLF

set objFile = objFSO.OpenTextFile("approved.txt", ForReading)
do until objFile.AtEndofStream
fileLine = objFile.ReadLine
if trim(fileLine)<> "" then ApprovedUpdates.add fileLine, fileLine
loop
objFile.Close

Wscript.echo "Getting list of denied updates..." & vbcrlf

set objFile = objFSO.OpenTextFile("denied.txt", ForReading)
do until objFile.AtEndofStream
fileLine = objFile.ReadLine
if trim(fileLine)<> "" then DeniedUpdates.add fileLine, fileLine
loop
objFile.Close

WScript.Echo "Searching for updates..." & vbCRLFSet

Set objResults = objSearcher.Search("IsInstalled=0 and Type='Software'")
Set colUpdates = objResults.Updates

if colUpdates.count = 0 then
Wscript.echo "No applicable updates to install."
wscript.quit
end if

WScript.Echo vbCRLF & "Creating collection of updates to download:"
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

For i = 0 to colUpdates.Count - 1
Wscript.Echo "Title: " & colUpdates.Item(i).Title
Wscript.Echo "KB article: " & strArticle
For Each strArticle in colUpdates.Item(i).KBArticleIDs
if not DeniedUpdates.Exists(strArticle) then
Wscript.Echo "Added to download list"
updatesToDownload.Add(update)
else
Wscript.Echo "Update not added found on Denied List"
end if
Next
Next

WScript.Echo vbCRLF & "Downloading updates..."
Set downloader = objSearcher.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()

WScript.Echo vbCRLF & "List of downloaded updates:"

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded Then
WScript.Echo I + 1 & "> " & update.Title
End If
Next


WScript.Echo "Installing updates..."

For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
WScript.Echo I + 1 & "> adding: " & update.Title
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
updatesToInstall.Add(update)

Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()

'Output results of install
WScript.Echo "Installation Result: " & installationResult.ResultCode
WScript.Echo "Reboot Required: " & installationResult.RebootRequired & vbCRLF
WScript.Echo "Listing of updates installed and individual installation results:"
For I = 0 to updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & updatesToInstall.Item(i).Title & ": " & installationResult.GetUpdateResult(i).ResultCode
Next
End If
Next

Link to comment
Share on other sites

  • 5 months later...

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
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.


×
×
  • Create New...