Seite 1 von 2
benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script WUA.vbs[gelöst]
Verfasst: 22.04.2024, 15:44
von Holgi
moin Deskmodder,
kennt sich jemand von euch etwas mit Visual Basic aus und kann das folgende Script so abändern das
alle Updates automatisch heruntergeladen werden und zwar ohne User-Interaktion?
Es ist ein Original MS Script aus der Windows Server Core Edition, welches aber wohl für alle Windows Editionen funktioniert.
Es wird gestartet mit
Außer den Hinweisen, was gerade passiert (z.B. "Updates werden heruntergeladen..." , "Updates wurden installiert", ggf. "Neustart erforderlich"), soll keine Bildschirmausgabe erfolgen.
Hier das OriginalScript:
WUA_SearchDownloadInstall.vbs
Code: Alles auswählen
'-------------------------------------------
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' Version 2.0
' WUA_SearchDownloadInstall.vbs - Script will query the Windows Update
' servers, display the applicable updates, download and install updates.
'
'-------------------------------------------
on error resume next
const L_Msg01_Text = "Empfohlene Updates werden gesucht..."
const L_Msg02_Text = "Liste geeigneter Elemente auf dem Computer:"
const L_Msg03_Text = "Keine geeigneten Updates vorhanden."
const L_Msg04_Text = "Drücken Sie zum Fortfahren die EINGABETASTE..."
const L_Msg05_Text = "Wählen Sie eine Option aus:"
const L_Msg06_Text = "Updates werden heruntergeladen..."
const L_Msg07_Text = "Updates werden installiert..."
const L_Msg08_Text = "Liste mit installierten Updates und individuellen Installationsergebnissen:"
const L_Msg09_Text = "Installationsergebnis: "
const L_Msg10_Text = "Neustart erforderlich: "
const L_Msg11_Text = "Zum Abschließen von Windows Updates ist ein Neustart erforderlich. Jetzt neu starten?"
const L_Msg12_Text = "Drücken Sie zum Fortfahren die EINGABETASTE..."
const L_Msg13_Text = "Nicht gestartet"
const L_Msg14_Text = "In Bearbeitung"
const L_Msg15_Text = "Erfolgreich"
const L_Msg16_Text = "Erfolgreich mit Fehlern"
const L_Msg17_Text = "Fehler"
const L_Msg18_Text = "Vorgang vorzeitig beendet"
const L_Msg19_Text = "Neustart erforderlich"
const L_Msg20_Text = "N" 'No
const L_Msg21_Text = "J" 'Yes
const L_Msg22_Text = "Alle geeigneten Updates werden gesucht..."
const L_Msg23_Text = "Nach (a)llen oder nur nach (e)mpfohlenen Updates suchen? "
const L_Msg24_Text = "A" ' All
const L_Msg25_Text = "E" ' Recommended only
const L_Msg26_Text = "B" ' Single update only
const L_Msg27_Text = "Geben Sie die Nummer des Updates ein, das heruntergeladen und installiert werden soll:"
const L_Msg28_Text = "(A)lle Updates, kei(n)e Updates oder (b)estimmtes Update? "
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set oShell = WScript.CreateObject ("WScript.shell")
Do
wscript.StdOut.Write L_Msg23_Text
UpdatesToSearch = ucase(Wscript.StdIn.ReadLine)
WScript.Echo
Select Case UpdatesToSearch
Case L_Msg24_Text 'All
WScript.Echo L_Msg22_Text & vbCRLF
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
Case L_Msg25_Text ' Recommended
WScript.Echo L_Msg01_Text & vbCRLF
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software' and AutoSelectOnWebsites=1")
Case Else
'
end Select
Loop until UpdatesToSearch=L_Msg24_Text or UpdatesToSearch=L_Msg25_Text
WScript.Echo L_Msg02_Text
WScript.Echo
For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
WScript.Echo I + 1 & "> " & update.Title
Next
SingleUpdateSelected=""
If searchResult.Updates.Count = 0 Then
WScript.Echo
WScript.Echo L_Msg03_Text
WScript.Echo
wscript.StdOut.Write L_Msg04_Text
Wscript.StdIn.ReadLine
WScript.Quit
else
'Select updates to download
do
WScript.Echo vbCRLF & L_Msg05_Text
Wscript.StdOut.Write L_Msg28_Text
UpdateSelection = ucase(WScript.StdIn.Readline)
WScript.Echo
loop until UpdateSelection=ucase(L_Msg20_Text) or UpdateSelection=ucase(L_Msg24_Text) or UpdateSelection=ucase(L_Msg26_Text)
If UpdateSelection=ucase(L_Msg20_Text) Then 'No updates
WScript.Quit
end if
If UpdateSelection=ucase(L_Msg26_Text) Then 'Single update
Do
WScript.Echo vbCRLF & L_Msg27_Text
SingleUpdateSelected = WScript.StdIn.Readline
loop until cint(SingleUpdateSelected) > 0 and cint(SingleUpdateSelected) <= searchResult.Updates.Count
end if
End If
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to searchResult.Updates.Count-1
if SingleUpdateSelected="" then
Set update = searchResult.Updates.Item(I)
updatesToDownload.Add(update)
else
if I=cint(SingleUpdateSelected)-1 then
Set update = searchResult.Updates.Item(I)
updatesToDownload.Add(update)
end if
end if
Next
WScript.Echo vbCRLF & L_Msg06_Text
WScript.Echo
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
'Creating collection of downloaded updates to install
For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
updatesToInstall.Add(update)
End If
Next
WScript.Echo
WScript.Echo L_Msg07_Text & vbCRLF
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
WScript.Echo L_Msg08_Text & vbCRLF
For I = 0 to updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & _
updatesToInstall.Item(i).Title & _
": " & ResultCodeText(installationResult.GetUpdateResult(i).ResultCode)
Next
'Output results of install
WScript.Echo
WScript.Echo L_Msg09_Text & ResultCodeText(installationResult.ResultCode)
WScript.Echo L_Msg10_Text & installationResult.RebootRequired & vbCRLF
If installationResult.RebootRequired then
confirm = msgbox(L_Msg11_Text, vbYesNo+vbDefaultButton2+vbSystemModal,L_Msg19_Text)
if confirm=vbYes then oShell.Run "shutdown /r /t 0",1
end if
WScript.Echo
Wscript.StdOut.Write L_Msg12_Text
Wscript.StdIn.ReadLine
WScript.Quit
Function ResultCodeText(resultcode)
if resultcode=0 then ResultCodeText=L_Msg13_Text
if resultcode=1 then ResultCodeText=L_Msg14_Text
if resultcode=2 then ResultCodeText=L_Msg15_Text
if resultcode=3 then ResultCodeText=L_Msg16_Text
if resultcode=4 then ResultCodeText=L_Msg17_Text
if resultcode=5 then ResultCodeText=L_Msg18_Text
end Function
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 22.04.2024, 15:59
von Tekkie Boy
Das Thema hattest Du doch schon einmal und auch irgendwas gefunden:
viewtopic.php?t=28496
Hat sich da irgendwas geändert?
🤔
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 22.04.2024, 16:09
von g-force
Probier mal aus:
Code: Alles auswählen
'-------------------------------------------
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' Version 2.0
' WUA_SearchDownloadInstall.vbs - Script will query the Windows Update
' servers, display the applicable updates, download and install updates.
'
'-------------------------------------------
On Error Resume Next
Const L_Msg01_Text = "Empfohlene Updates werden gesucht..."
Const L_Msg02_Text = "Liste geeigneter Elemente auf dem Computer:"
Const L_Msg03_Text = "Keine geeigneten Updates vorhanden."
Const L_Msg04_Text = "Drücken Sie zum Fortfahren die EINGABETASTE..."
Const L_Msg05_Text = "Wählen Sie eine Option aus:"
Const L_Msg06_Text = "Updates werden heruntergeladen..."
Const L_Msg07_Text = "Updates werden installiert..."
Const L_Msg08_Text = "Liste mit installierten Updates und individuellen Installationsergebnissen:"
Const L_Msg09_Text = "Installationsergebnis: "
Const L_Msg10_Text = "Neustart erforderlich: "
Const L_Msg11_Text = "Zum Abschließen von Windows Updates ist ein Neustart erforderlich. Jetzt neu starten?"
Const L_Msg12_Text = "Drücken Sie zum Fortfahren die EINGABETASTE..."
Const L_Msg13_Text = "Nicht gestartet"
Const L_Msg14_Text = "In Bearbeitung"
Const L_Msg15_Text = "Erfolgreich"
Const L_Msg16_Text = "Erfolgreich mit Fehlern"
Const L_Msg17_Text = "Fehler"
Const L_Msg18_Text = "Vorgang vorzeitig beendet"
Const L_Msg19_Text = "Neustart erforderlich"
Const L_Msg20_Text = "N" 'No
Const L_Msg21_Text = "J" 'Yes
Const L_Msg22_Text = "Alle geeigneten Updates werden gesucht..."
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set oShell = WScript.CreateObject ("WScript.shell")
' Automatically select all updates
WScript.Echo L_Msg22_Text & vbCRLF
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
WScript.Echo L_Msg02_Text
WScript.Echo
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
WScript.Echo L_Msg03_Text
WScript.Echo
WScript.Quit
End If
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to searchResult.Updates.Count - 1
Set update = searchResult.Updates.Item(I)
updatesToDownload.Add(update)
Next
WScript.Echo vbCRLF & L_Msg06_Text
WScript.Echo
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
'Creating collection of downloaded updates to install
For I = 0 To searchResult.Updates.Count - 1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded = True Then
updatesToInstall.Add(update)
End If
Next
WScript.Echo
WScript.Echo L_Msg07_Text & vbCRLF
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
WScript.Echo L_Msg08_Text & vbCRLF
For I = 0 To updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & _
updatesToInstall.Item(i).Title & _
": " & ResultCodeText(installationResult.GetUpdateResult(i).ResultCode)
Next
'Output results of install
WScript.Echo
WScript.Echo L_Msg09_Text & ResultCodeText(installationResult.ResultCode)
WScript.Echo L_Msg10_Text & installationResult.RebootRequired & vbCRLF
If installationResult.RebootRequired Then
oShell.Run "shutdown /r /t 0", 1
End If
WScript.Quit
Function ResultCodeText(resultcode)
If resultcode = 0 Then ResultCodeText = L_Msg13_Text
If resultcode = 1 Then ResultCodeText = L_Msg14_Text
If resultcode = 2 Then ResultCodeText = L_Msg15_Text
If resultcode = 3 Then ResultCodeText = L_Msg16_Text
If resultcode = 4 Then ResultCodeText = L_Msg17_Text
If resultcode = 5 Then ResultCodeText = L_Msg18_Text
End Function
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 22.04.2024, 16:22
von Holgi
Tekkie Boy hat geschrieben: 22.04.2024, 15:59
Das Thema hattest Du doch schon einmal und auch irgendwas gefunden:
Hat sich da irgendwas geändert?
🤔
gut aufgepasst! Danke.
Das Script läuft nur suboptimal; zumindest, wenn es keine Updates z.Zt. gibt.
Die Ausgabe sieht dann so aus:
Updates Script1.JPG
Liste geeigneter Elemente auf dem Computer macht da keinen Sinn.
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 22.04.2024, 16:25
von Holgi
g-force hat geschrieben: 22.04.2024, 16:09
Probier mal aus:
Updates Script2.JPG
Das ist schon besser; es erscheint "keine geeigneten Updates vorhanden" was gut ist.
Was mich stört ist die Zeile
"Liste geeigneter Elemente auf dem Computer"
Kann man das noch wegbekommen, wenn sowieso keine Updates vorliegen?
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 22.04.2024, 16:45
von g-force
Code: Alles auswählen
'-------------------------------------------
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' Version 2.0
' WUA_SearchDownloadInstall.vbs - Script will query the Windows Update
' servers, display the applicable updates, download and install updates.
'
'-------------------------------------------
On Error Resume Next
Const L_Msg01_Text = "Empfohlene Updates werden gesucht..."
Const L_Msg02_Text = "Liste geeigneter Elemente auf dem Computer:"
Const L_Msg04_Text = "Drücken Sie zum Fortfahren die EINGABETASTE..."
Const L_Msg05_Text = "Wählen Sie eine Option aus:"
Const L_Msg06_Text = "Updates werden heruntergeladen..."
Const L_Msg07_Text = "Updates werden installiert..."
Const L_Msg08_Text = "Liste mit installierten Updates und individuellen Installationsergebnissen:"
Const L_Msg09_Text = "Installationsergebnis: "
Const L_Msg10_Text = "Neustart erforderlich: "
Const L_Msg11_Text = "Zum Abschließen von Windows Updates ist ein Neustart erforderlich. Jetzt neu starten?"
Const L_Msg12_Text = "Drücken Sie zum Fortfahren die EINGABETASTE..."
Const L_Msg13_Text = "Nicht gestartet"
Const L_Msg14_Text = "In Bearbeitung"
Const L_Msg15_Text = "Erfolgreich"
Const L_Msg16_Text = "Erfolgreich mit Fehlern"
Const L_Msg17_Text = "Fehler"
Const L_Msg18_Text = "Vorgang vorzeitig beendet"
Const L_Msg19_Text = "Neustart erforderlich"
Const L_Msg20_Text = "N" 'No
Const L_Msg21_Text = "J" 'Yes
Const L_Msg22_Text = "Alle geeigneten Updates werden gesucht..."
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set oShell = WScript.CreateObject ("WScript.shell")
' Automatically select all updates
WScript.Echo L_Msg22_Text & vbCRLF
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
WScript.Echo L_Msg02_Text
WScript.Echo
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.Quit
End If
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to searchResult.Updates.Count - 1
Set update = searchResult.Updates.Item(I)
updatesToDownload.Add(update)
Next
WScript.Echo vbCRLF & L_Msg06_Text
WScript.Echo
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
'Creating collection of downloaded updates to install
For I = 0 To searchResult.Updates.Count - 1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded = True Then
updatesToInstall.Add(update)
End If
Next
WScript.Echo
WScript.Echo L_Msg07_Text & vbCRLF
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
WScript.Echo L_Msg08_Text & vbCRLF
For I = 0 To updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & _
updatesToInstall.Item(i).Title & _
": " & ResultCodeText(installationResult.GetUpdateResult(i).ResultCode)
Next
'Output results of install
WScript.Echo
WScript.Echo L_Msg09_Text & ResultCodeText(installationResult.ResultCode)
WScript.Echo L_Msg10_Text & installationResult.RebootRequired & vbCRLF
If installationResult.RebootRequired Then
oShell.Run "shutdown /r /t 0", 1
End If
WScript.Quit
Function ResultCodeText(resultcode)
If resultcode = 0 Then ResultCodeText = L_Msg13_Text
If resultcode = 1 Then ResultCodeText = L_Msg14_Text
If resultcode = 2 Then ResultCodeText = L_Msg15_Text
If resultcode = 3 Then ResultCodeText = L_Msg16_Text
If resultcode = 4 Then ResultCodeText = L_Msg17_Text
If resultcode = 5 Then ResultCodeText = L_Msg18_Text
End Function
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 22.04.2024, 17:33
von Holgi
ist nicht besser geworden:
Updates Script3.JPG
"Liste geeigneter Updates" erscheint immer noch
und darüberhinaus ist
"keine geeigneten Updates vorhanden"
weggefallen.
Da war das vorherige Script besser.
Vlt könnte man hinter "Liste" wenigstens eine Anzahl angeben lassen, damit es Sinn ergibt:
so in der Art:
"Liste geeigneter Updates: 0"
Keine Ahnung, wie/wo das Script die Anzahl auslesen kann.
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 22.04.2024, 22:17
von Holgi
vlt. so in dieser Art:
Code: Alles auswählen
Set updateSession = CreateObject("Microsoft.Update.Session")
updateSession.ClientApplicationID = "MSDN Sample Script"
Set updateSearcher = updateSession.CreateUpdateSearcher()
WScript.Echo "Alle geeigneten Updates werden gesucht..." & vbCRLF
Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
WScript.Echo "Liste geeigneter Updates:"
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 "Keine 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)"
' Abfrage wird übersprungen und Wert manuell gesetzt
'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..."
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
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)"
' Abfrage wird übersprungen und Wert manuell gesetzt
'strInput = WScript.StdIn.Readline
strInput = "Y"
WScript.Echo
If (strInput = "Y" or strInput = "y") Then
WScript.Echo "Installing updates..."
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
'Output results of install
WScript.Echo "Installation Result: " & _
installationResult.ResultCode
WScript.Echo "Reboot Required: " & _
installationResult.RebootRequired & vbCRLF
WScript.Echo "Listing of updates installed " & _
"and individual installation results:"
For I = 0 to updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & _
updatesToInstall.Item(i).Title & _
": " & installationResult.GetUpdateResult(i).ResultCode
Next
End If
'Reboot ergänzt!
If rebootMayBeRequired = true Then
WScript.Echo vbCRLF & "Start Reboot ..."
Set WSHShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 120"
End If
fehlt nur noch ein schöner Exit, damit das Script-Fenster geschlossen wird.
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 23.04.2024, 13:31
von g-force
Hast Du mal "ChatGP" für sowas bemüht?
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 23.04.2024, 13:37
von Holgi
Hatte ich auch schon gedacht.
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 25.04.2024, 14:31
von Holgi
vlt. kann das mal bitte jemand für mich testen?
insbesondere daraufhin, ob auch die Virensignaturen und KB890830 (MSRT/MRT.exe) aktualisiert wird. Danke!
WUA_SearchDownloadInstall.vbs
Code: Alles auswählen
Set updateSession = CreateObject("Microsoft.Update.Session")
updateSession.ClientApplicationID = "MSDN Sample Script"
Set updateSearcher = updateSession.CreateUpdateSearcher()
WScript.Echo "Alle geeigneten Updates werden gesucht..." & vbCRLF
Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
WScript.Echo "Liste geeigneter Updates:"
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 "Keine Updates!"
WScript.Timeout = 5
do while true
loop
sub WScript_timeout()
msgbox("OK")
end sub
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)"
' Abfrage wird übersprungen und Wert manuell gesetzt
'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..."
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
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)"
' Abfrage wird übersprungen und Wert manuell gesetzt
'strInput = WScript.StdIn.Readline
strInput = "Y"
WScript.Echo
If (strInput = "Y" or strInput = "y") Then
WScript.Echo "Installing updates..."
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
'Output results of install
WScript.Echo "Installation Result: " & _
installationResult.ResultCode
WScript.Echo "Reboot Required: " & _
installationResult.RebootRequired & vbCRLF
WScript.Echo "Listing of updates installed " & _
"and individual installation results:"
For I = 0 to updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & _
updatesToInstall.Item(i).Title & _
": " & installationResult.GetUpdateResult(i).ResultCode
Next
End If
'Reboot ergänzt!
If rebootMayBeRequired = true Then
WScript.Echo vbCRLF & "Start Reboot ..."
Set WSHShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 120"
End If
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)"
' Abfrage wird übersprungen und Wert manuell gesetzt
'strInput = WScript.StdIn.Readline
strInput = "Y"
WScript.Echo
If (strInput = "Y" or strInput = "y") Then
WScript.Echo "Installing updates..."
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
'Output results of install
WScript.Echo "Installation Result: " & _
installationResult.ResultCode
WScript.Echo "Reboot Required: " & _
installationResult.RebootRequired & vbCRLF
WScript.Echo "Listing of updates installed " & _
"and individual installation results:"
For I = 0 to updatesToInstall.Count - 1
WScript.Echo I + 1 & "> " & _
updatesToInstall.Item(i).Title & _
": " & installationResult.GetUpdateResult(i).ResultCode
Next
End If
'Reboot ergänzt!
If rebootMayBeRequired = true Then
WScript.Echo vbCRLF & "Start Reboot ..."
Set WSHShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 120"
End If
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 25.04.2024, 20:33
von g-force
Holgi_1.PNG
Holgi_2.PNG
Holgi_3.PNG
Holgi_4.PNG
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 25.04.2024, 20:36
von g-force
Was hast Du grundsätzlich vor mit dem Script? Möchtest Du ein automatisches Update, möglichst ohne User-Eingriff? Oder lieber wie in deinem Script mit einigen Abfragen bzw. Bestätigungen? Bei deinem Script muß ich 6-8 mal auf "OK" klicken, beim ersten Versuch hatte ich erstmal ewig auf einen automatischen Fortschritt gewartet.
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 25.04.2024, 22:51
von Holgi
Die ganzen Abfragen, wie bei dir kommen bei mir gar nicht! Kömisch.
Adminrechte?
Hast du diese Fenster auch beim Originalscript?
Der Sinn dahinter liegt ja gerade darin, dass Ganze ohne Abfragen zu automatisieren. Z.B auf einem Server Core.
Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script
Verfasst: 26.04.2024, 09:14
von Holgi
g-force hat geschrieben: 25.04.2024, 20:36
Bei deinem Script muß ich 6-8 mal auf "OK" klicken, beim ersten Versuch hatte ich erstmal ewig auf einen automatischen Fortschritt gewartet.
@g-force:
den ersten Beitrag hast du aber schon gelesen, oder?
viewtopic.php?t=31766#p426978
das Script wird mit
Code: Alles auswählen
c:\Windows\System32\cscript.exe "%~dp0WUA_SearchDownloadInstall.vbs"
oder
Code: Alles auswählen
c:\Windows\System32\cscript.exe "Pfad zur vbs"\WUA_SearchDownloadInstall.vbs"
aufgerufen.
Wenn du es per Doppelclick aufruft, dann läuft das nicht als Command-Script, sondern als W-Script (Windows-Script).
Dann kommen die von dir beschriebenen Fenster.