MattHiggs Posted October 29, 2017 Posted October 29, 2017 (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. expandcollapse popup#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.au3Fetching info... Edited October 29, 2017 by MattHiggs mLipok, coffeeturtle and argumentum 3
argumentum Posted October 29, 2017 Posted October 29, 2017 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 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
MattHiggs Posted October 29, 2017 Author Posted October 29, 2017 On 10/29/2017 at 2:38 PM, 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 Expand 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.
MattHiggs Posted October 29, 2017 Author Posted October 29, 2017 Original post edited to present prompt before update download as well coffeeturtle and argumentum 2
qwert Posted October 29, 2017 Posted October 29, 2017 Thanks for this script. I do have two questions: Quote It also lets you choose the "source" you obtain the updates from. Expand 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?
MattHiggs Posted October 29, 2017 Author Posted October 29, 2017 On 10/29/2017 at 10:30 PM, 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? Expand To answer your first question, see below:
qwert Posted October 29, 2017 Posted October 29, 2017 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.
MattHiggs Posted October 29, 2017 Author Posted October 29, 2017 On 10/29/2017 at 11:47 PM, 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. Expand 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 = ????
qwert Posted October 30, 2017 Posted October 30, 2017 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.
marcgforce Posted November 5, 2017 Posted November 5, 2017 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
MattHiggs Posted November 7, 2017 Author Posted November 7, 2017 On 11/5/2017 at 10: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 Expand #requireadmin shouldn't be required. You can install updates without admin rights. I am interested to know what update caused the crash...
marcgforce Posted November 7, 2017 Posted November 7, 2017 if i remeber it was a update of flashplayer
MattHiggs Posted November 24, 2017 Author Posted November 24, 2017 On 11/7/2017 at 9:56 PM, marcgforce said: if i remeber it was a update of flashplayer Expand 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. coffeeturtle 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now