Set args = WScript.Arguments Dim kickstartInstallationId, securityKey, updateKickstartInstallationStatusUrl ' Make sure we have the 3 arguments If args.Count >= 3 Then kickstartInstallationId = args(0) securityKey = args(1) updateKickstartInstallationStatusUrl = args(2) Else WScript.Echo "Missing arguments" WScript.Quit End If WScript.Echo "kickstartInstallationId:" + kickstartInstallationId WScript.Echo "securityKey:" + securityKey WScript.Echo "updateKickstartInstallationStatusUrl:" + updateKickstartInstallationStatusUrl Set oX = CreateObject("MSXML2.ServerXMLHTTP.3.0") Dim statusUrl statusUrl = updateKickstartInstallationStatusUrl & "?kickstartInstallationId=" & kickstartInstallationId statusUrl = statusUrl & "&securityKey=" & securityKey & "&percentComplete=60&message=Installing%20Updates" oX.Open "GET", statusUrl, False oX.Send WScript.Echo oX.responseText & vbCRLF ' Download and Install updates Set updateSession = CreateObject("Microsoft.Update.Session") updateSession.ClientApplicationID = "MSDN Sample Script" Set updateSearcher = updateSession.CreateUpdateSearcher() WScript.Echo "Searching for updates..." & vbCRLF Set searchResult = _ updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0") 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) addThisUpdate = false If update.InstallationBehavior.CanRequestUserInput = true Then WScript.Echo I + 1 & "> skipping: " & update.Title & _ " because it requires user input" Else If update.EulaAccepted = false Then WScript.Echo I + 1 & "> note: " & update.Title & _ " has a license agreement that must be accepted:" WScript.Echo update.EulaText WScript.Echo "Do you accept this license agreement? (Y/N)" 'strInput = WScript.StdIn.Readline strInput = "Y" WScript.Echo If (strInput = "Y" or strInput = "y") Then update.AcceptEula() addThisUpdate = true Else WScript.Echo I + 1 & "> skipping: " & update.Title & _ " because the license agreement was declined" End If Else addThisUpdate = true End If End If If addThisUpdate = true Then WScript.Echo I + 1 & "> adding: " & update.Title updatesToDownload.Add(update) End If Next If updatesToDownload.Count = 0 Then WScript.Echo "All applicable updates were skipped." WScript.Quit End If WScript.Echo vbCRLF & "Downloading updates... (" & updatesToDownload.Count-1 & ")" ' Downloading Updates goes from percent 50 - 70 ' Only send updates for each new percent Set downloader = updateSession.CreateUpdateDownloader() lastPercent = 0 currentPercent = 0 For I = 0 To updatesToDownload.Count-1 WScript.Echo vbCRLF & "Downloading update " & I+1 & "/" & updatesToDownload.Count Set currentUpdateToDownload = CreateObject("Microsoft.Update.UpdateColl") lastPercent = currentPercent currentPercent = Int(60 + 12.0 * I / (updatesToDownload.Count-1)) statusUrl = updateKickstartInstallationStatusUrl & "?kickstartInstallationId=" & kickstartInstallationId & "&securityKey=" & securityKey statusUrl = statusUrl & "&message=Downloading%20Updates%20" & I+1 & "%2F" & updatesToDownload.Count statusUrl = statusUrl & "&percentComplete=" & currentPercent If lastPercent <> currentPercent Then WScript.Echo vbCRLF & statusUrl oX.Open "GET", statusUrl, False oX.Send WScript.Echo oX.responseText & vbCRLF End If currentUpdateToDownload.Add(updatesToDownload.Item(I)) downloader.Updates = currentUpdateToDownload downloader.Download() Next Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl") rebootMayBeRequired = false WScript.Echo vbCRLF & "Successfully downloaded updates:" For I = 0 To searchResult.Updates.Count-1 set update = searchResult.Updates.Item(I) If update.IsDownloaded = true Then WScript.Echo I + 1 & "> " & update.Title updatesToInstall.Add(update) If update.InstallationBehavior.RebootBehavior > 0 Then rebootMayBeRequired = true End If End If Next If updatesToInstall.Count = 0 Then WScript.Echo "No updates were successfully downloaded." WScript.Quit End If If rebootMayBeRequired = true Then WScript.Echo vbCRLF & "These updates may require a reboot." End If WScript.Echo vbCRLF & "Would you like to install updates now? (Y/N)" 'strInput = WScript.StdIn.Readline strInput = "Y" WScript.Echo ' Installing updates from 71 - 90 Set installer = updateSession.CreateUpdateInstaller() lastPercent = 0 currentPercent = 0 If (strInput = "Y" or strInput = "y") Then For I = 0 To updatesToInstall.Count-1 WScript.Echo vbCRLF & "Installing update " & I+1 & "/" & updatesToInstall.Count Set currentUpdateToInstall = CreateObject("Microsoft.Update.UpdateColl") lastPercent = currentPercent currentPercent = Int(72 + 13.0 * I / (updatesToInstall.Count-1)) statusUrl = updateKickstartInstallationStatusUrl &"?kickstartInstallationId=" & kickstartInstallationId & "&securityKey=" & securityKey statusUrl = statusUrl & "&message=Installing%20Updates%20" & I+1 & "%2F" & updatesToInstall.Count statusUrl = statusUrl & "&percentComplete=" & currentPercent If lastPercent <> currentPercent Then WScript.Echo vbCRLF & statusUrl oX.Open "GET", statusUrl, False oX.Send WScript.Echo oX.responseText & vbCRLF End If currentUpdateToInstall.Add(updatesToInstall.Item(I)) installer.Updates = currentUpdateToInstall Set installationResult = installer.Install() 'Output results of install WScript.Echo "Installation Result: " & _ installationResult.ResultCode WScript.Echo "Reboot Required: " & _ installationResult.RebootRequired & vbCRLF WScript.Echo "Update installation is completed!!!!" Next End If WScript.Echo "All update are successfully installed!" statusUrl = updateKickstartInstallationStatusUrl & "?kickstartInstallationId=" & kickstartInstallationId statusUrl = statusUrl & "&securityKey=" & securityKey & "&percentComplete=95&message=Finalizing%20Installation" oX.Open "GET", statusUrl, False oX.Send WScript.Echo oX.responseText & vbCRLF Function getCommandOutput(theCommand) Dim objShell, objCmdExec Set objShell = CreateObject("WScript.Shell") Set objCmdExec = objshell.exec(thecommand) getCommandOutput = objCmdExec.StdOut.ReadAll end Function