Dies ist ein WSH Script das die Windowsupdates installiert die schon auf dem Computer heruntergeladen wurden.
Will mann vorher alle Upates per Befehl runterladen kann man „wuauclt /detectnow“ machen. Danach muss man aber warten bis dieses im Hintergrund heruntergeladen wurden. Indikator hierfür ist ob der Task wuauclt.exe noch aktiv ist.
Dies ist das Script:
Set updateSession = CreateObject("Microsoft.Update.Session")
updateSession.ClientApplicationID = "MSDN Sample Script"
Set updateSearcher = updateSession.CreateUpdateSearcher()
Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
Next
If searchResult.Updates.Count = 0 Then
WScript.Quit
End If
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
Else
If update.EulaAccepted = false Then
update.AcceptEula()
addThisUpdate = true
Else
addThisUpdate = true
End If
End If
If addThisUpdate = true Then
updatesToDownload.Add(update)
End If
Next
If updatesToDownload.Count = 0 Then
WScript.Quit
End If
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
rebootMayBeRequired = false
For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
updatesToInstall.Add(update)
If update.InstallationBehavior.RebootBehavior > 0 Then
rebootMayBeRequired = true
End If
End If
Next
If updatesToInstall.Count = 0 Then
WScript.Quit
End If
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
Setzt man einen WSUS ein kann man im Anschluss noch einen „wuauclt /reportnow“ absetzen um dem WSUS die aktuellen Updateinformationen zukommen zu lassen.