Command line windows updates

Soldato
Joined
17 Jul 2008
Posts
7,437
Does anyone know of a free program that will install windows updates?

After I have installed a machine I just want to stick a batch file in startup that will trundle off and install updates hopefully to reboot as needed and continue the process
 
You could use Group Policy to configure the update and force a reboot.

Other than that there is no real way of "Automating" the whole process. Not at the risk of totally shagging the OS install by using 3rd party tools/scripts to mess about with WU.

You can do some scripting of Windows Update but they mainly just adjust what you can see with Group Policy anyway.
 
Last edited:
command line tool for windows updates

Does anyone know of a free program that will install windows updates?

After I have installed a machine I just want to stick a batch file in startup that will trundle off and install updates hopefully to reboot as needed and continue the process

you could use the command line tool wuinstall. i use it to update remotely machines via psexec. it has several more options than the microsoft alternative. also, as you mentioned, for example the reboots can be triggered automatically.
 
Code:
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
Save that as update.vbs and call it via a dos prompt or batch file.
cscript update.vbs



Its a MS script and what we use on our scripted XP installs, it works very well and negate the need for any 3rd party program.
 
Last edited:
Back
Top Bottom