Jump to content

Recommended Posts

Posted (edited)

Found a visual basic script online which searches for, downloads, and installs all available Windows updates available for the current operating system.  It also lets you choose the "source" you obtain the updates from.  I wanted to convert it over to autoit and share, as this was the only missing piece in my automated os deployment script, which is now complete..  Note that you will need attached udf for script to work.  The original vbscript can be found here.  All credit goes to author of original script.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
;ServerSelection values
#include <console.au3>
$ssDefault = 0
$ssManagedServer = 1
$ssWindowsUpdate = 2
$ssOthers = 3


$intSearchStartChar = 1
Local $strTitle
Cout ( "searching for updates..." & @CRLF )
$updateSession = ObjCreate("Microsoft.Update.Session")
$updateSearcher = $updateSession.CreateupdateSearcher()
$updateSearcher.ServerSelection = $ssWindowsUpdate
$searchResult = $updateSearcher.Search("IsInstalled=0 and Type='Software'")
cout ( "List of applicable items on the machine:" & @CRLF & @CRLF )
For $i = 0 to Int ( $searchResult.Updates.Count ) - 1 Step 1
    $update = $searchResult.Updates.Item($i)
    cout ( ( $i + 1 ) & ".  " & $update.Title & @CRLF )
Next
If Int ( $searchResult.Updates.Count ) = 0 Then
    cout ( "There are no applicable updates." & @CRLF )
    Exit
EndIf
cout ( "Creating collection of updates to download:" & @CRLF & @CRLF )
$updatesToDownload = ObjCreate("Microsoft.Update.UpdateColl")
For $i = 0 to Int ( $searchResult.Updates.Count ) - 1 Step 1
    $update = $searchResult.Updates.Item($i)
    $addThisUpdate = false
    If $update.InstallationBehavior.CanRequestUserInput = true Then
        cout ( $i + 1 & ".  skipping: " & $update.Title & " because it requires user input" & @CRLF )
    Else
        If $update.EulaAccepted = false Then
            $update.AcceptEula()
            $addThisUpdate = true
        Else
            $addThisUpdate = True
        EndIf
    EndIf
    If $addThisUpdate = true Then
        cout ( ( $i + 1 ) & ".  adding: " & $update.Title & @CRLF )
        $updatesToDownload.Add($update)
    EndIf
Next
If $updatesToDownload.Count = 0 Then
    cout ( "All updates were skipped" & @CRLF )
    Exit
EndIf
Cout ( "Would you like to download available updates?  (Y/N)" & @CRLF )
$input2 = Getch ()
If $input2 <> "y" And $input2 <> "Y" Then
    Cout ( "Either invalid input was entered or you chose not to install.  Exiting.." & @CRLF )
    Exit
Else
cout ( "Downloading updates..." & @CRLF )
$downloader = $updateSession.CreateUpdateDownloader()
$downloader.Updates = $updatesToDownload
$downloader.Download()
$updatesToInstall = ObjCreate ("Microsoft.Update.UpdateColl")
$rebootMayBeRequired = false
cout ( "Successfully downloaded updates:" & @CRLF & @CRLF )
For $i = 0 to Int ( $searchResult.Updates.Count ) - 1 Step 1
    $update = $searchResult.Updates.Item($i)
    If $update.IsDownloaded = true Then
        cout ( ( $i + 1 ) & ".   " & $update.Title & @CRLF )
        $updatesToInstall.Add($update)
        If Int ( $update.InstallationBehavior.RebootBehavior ) > 0 Then
            $rebootMayBeRequired = true
        EndIf
    EndIf
Next
If $updatesToInstall.Count = 0 Then
    cout ( "No updates were successfully downloaded." & @CRLF )
    Exit
EndIf

If $rebootMayBeRequired = true Then
    cout ( "These updates may require a reboot." & @CRLF )
EndIf
Cout ( "Would you like to install updates now? (Y/N)" & @CRLF )
$input = Getch ( )
If $input <> "y" And $input <> "Y" Then
    Cout ( "Either invalid input was entered or you chose not to install.  Exiting.." & @CRLF )
    Exit
Else
    Cout ( "Installing updates..." & @CRLF )
    $installer = $updateSession.CreateUpdateInstaller()
    $installer.Updates = $updatesToInstall
    $installationResult = $installer.Install()
    cout ( "Installation Result: " & $installationResult.ResultCode & @CRLF )
    Cout ( "Reboot Required: " & $installationResult.RebootRequired & @CRLF )
    Cout ( "Listing of updates installed and individual installation results:" & @CRLF & @CRLF )
    For $i = 0 to Int ( $updatesToInstall.Count ) - 1 step 1
        Cout ( ( $i + 1 ) & ".   " & $updatesToInstall.Item($i).Title & ": " & $installationResult.GetUpdateResult($i).ResultCode & @CRLF )
    Next
EndIf
EndIf

 

Console.au3

Edited by MattHiggs
Posted

 

3 hours ago, argumentum said:

:)
There is a "Would you like to install updates now? (Y/N)", could it be an option to "Downloading updates...(Y/N)" ?
Thanks for sharing

I could add it.  In the script I use, I don't have any prompts at all, as I wanted to automate the process with 0 human interaction.  I added the install prompt in only for posting purposes, but can add the download prompt as well.

Posted

Thanks for this script.  I do have two questions:

Quote

It also lets you choose the "source" you obtain the updates from.

Can you point out where that occurs.

Also, do you know of a way to obtain a full description of each update? ... i.e., beyond the update's title?

 

Posted
8 minutes ago, qwert said:

Thanks for this script.  I do have two questions:

Can you point out where that occurs.

Also, do you know of a way to obtain a full description of each update? ... i.e., beyond the update's title?

 

To answer your first question, see below:

AnKHeGl.png

Posted

I'll have to investigate those choices, as they don't match up with anything I'm familiar with.  I've never had occasion to use ServerSelection, for example.

Thanks for your response.

Posted
2 minutes ago, qwert said:

I'll have to investigate those choices, as they don't match up with anything I'm familiar with.  I've never had occasion to use ServerSelection, for example.

Thanks for your response.

Default = Whatever the default is currently set as

Managedserver = Get available updates from WSUS server (which will retrieve only the updates which have been configured on a WSUS server)

WindowsUpdate = Get available windows updates from microsoft (which will list all updates available for your device)

other = ????

Posted

Yes, that helps.  It tells me that you pick from a "limited realm of choices" made available to your PC ... and not from "at large sources" from 3rd-party providers.

Thanks.

Posted
On 11/5/2017 at 5:52 PM, marcgforce said:

Hello guys, tested and aproved, simply one things to ad : 

 #RequireAdmin because of a crash line 75 trying to dl with an user profile

have a nice developpement

#requireadmin shouldn't be required.  You can install updates without admin rights.  I am interested to know what update caused the crash...

  • 3 weeks later...
Posted
On 11/7/2017 at 4:56 PM, marcgforce said:

if i remeber it was a update of flashplayer

Then the reason it probably crashed without admin rights is because flash player, being a third party application and not a windows update, would need admin rights in order to install.

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...