Skip to content

Instantly share code, notes, and snippets.

@cjerrington
Created August 8, 2016 15:04
Show Gist options
  • Select an option

  • Save cjerrington/92edc04c32d015e166bc395413c16fd4 to your computer and use it in GitHub Desktop.

Select an option

Save cjerrington/92edc04c32d015e166bc395413c16fd4 to your computer and use it in GitHub Desktop.
Windows Update across OS releases
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.2
Author: Clayton Errington
Script Function:
Run windows update across Windows 7, Windows 8, and Windows 10
#ce ----------------------------------------------------------------------------
; Create the Function
Func WindowsUpdate()
; Query WMI to get the version of Windows the client is using.
$colItems = ""
$Output=""
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", 0x30)
If IsObj($colItems) then
For $objItem In $colItems
$Output = $objItem.Caption
if $Output = "Microsoft Windows 10 Enterprise" Then
ShellExecute("ms-settings:windowsupdate")
ElseIf $Output = "Microsoft Windows 7 Enterprise" Then
Run("C:\Windows\system32\wuapp.exe")
Else
;Windows 8 uses the same EXE and path to run Windows Update.
Run("C:\Windows\system32\wuapp.exe")
$Output=""
EndIf
Next
Else
; Error: throw an error if the object cannont be found.
Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_OperatingSystem" )
Endif
EndFunc
;Run Function
WindowsUpdate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment