benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script [gelöst]

Antwort erstellen


Diese Frage dient dazu, das automatisierte Versenden von Formularen durch Spam-Bots zu verhindern.
Smileys
:) ;) :smile: :lol: :hihi: :D :rofl: :muahah: :( :pff: :kopfstreichel: :ohno: :betruebt: :heulen: :kopfkratz: :duckundweg: :o :? :oops: :psst: :sauer: :-P :daumenrunter: :daumen: :dankeschoen: :thx: :dafür: :gähn:
Mehr Smileys anzeigen

BBCode ist eingeschaltet
[img] ist eingeschaltet
[flash] ist ausgeschaltet
[url] ist eingeschaltet
Smileys sind eingeschaltet

Die letzten Beiträge des Themas

Ich habe die Datenschutzerklärung gelesen und bin damit einverstanden.

   

Ansicht erweitern Die letzten Beiträge des Themas: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script [gelöst]

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script [gelöst]

von Scoty » 12.05.2024, 12:15

@Holgi hatte endlich mal zeit das ganze zu testen und funktioniert super.
Screenshot 2024-05-12 121510.png
Screenshot 2024-05-12 121303.png
Screenshot 2024-05-12 121228.png

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script [gelöst]

von Holgi » 01.05.2024, 16:38

hier die Lösung:
Ein Script, welches ich @g-force schon mal 2022 vorgestellt hatte. Damals hatte ich selbst noch keine Verwendung dafür.
Jetzt noch mal ausgegraben:
viewtopic.php?p=383232#p383232
Das Schöne daran ist:
man kann es wunderbar in einer automatischen Windows Installation mit autounattend.xml und firstlogon.cmd (setupcomplete.cmd) einsetzen.
Dann werden die Windows Updates nach der Installation automatisch heruntergeladen, installiert und ggf. ein Neustart durchgeführt.
Deshalb (wegen möglichem Reboot) dann ganz am Ende der firstlogon.cmd diese Zeilen einfügen:

Code: Alles auswählen

C:\Windows\System32\cscript.exe "C:\Windows\System32\WUA.vbs" /automate /RebootToComplete
In diesem Beispiel wurde das WUA Update Script ind $OEM$\$$\System32 untergebracht. Kann man natürlich ändern, wenn man es gerne anderswo hätte.
Möchte man die Bildschirmausgaben des Scripts sehen, dann z.B. so aufrufen:
WindowsUpdate.cmd

Code: Alles auswählen

C:\Windows\System32\cscript.exe "C:\Windows\System32\WUA.vbs" /ShowDetails
pause
hier noch mal das VisualBasicScript in Gänze; jetzt mit deutschen Textausgaben von mir geändert.
WUA.vbs

Code: Alles auswählen

Option Explicit

' Supported parameters:
'    /AppName: Name to pass to the WUA API as the 'calling application';
'             this appears in the Windows Update logs
'             Default: "WUA API Sample Script"
'    /Criteria: Search criteria to be used (see the WUA documentation for
'             IUpdateSearcher::BeginSearch for examples)
'             Default: Search for all non-installed, non-hidden software
'    /Automate: Don't prompt the user for various actions
'             Default: Prompt the user
'    /IgnoreSupersedence: Display all applicable updates, even those
'             superseded by newer updates
'             Default: Ignore supersedes updates
'    /Offline: Path to WSUSSCN2.cab file that should be used for offline sync
'             Default: Don't do offline sync
'    /Service: Update service that script should scan against
'             Available values: WU, MU, WSUS, DCAT, STORE, or an
'             identifying GUID of another service
'             Default: Default service (WSUS if machine is configured to
'                 use it, or MU if opted in, or WU otherwise)
'             Ignored if /Offline is set
'    /Hide: Hide updates found by the scan. Hidden updates will not
'             normally be installed by Automatic Updates.
'    /Show: Unhide any hidden updates found by the scan.
'    /NoDownload: Do not download any updates that the scan detects
'    /NoInstall: Do not install any updates that the scan detects
'    /ShowDetails: Show details about the updates found by the scan
'    /ShowBundle: Output information about the child updates in the 
'             bundled updates that are found
'    /RebootToComplete: Restart the computer if necessary to complete
'             installation

Function InstallationResultToText(result)
    Select Case result
        Case 2
            InstallationResultToText = "Succeeded"
        Case 3
            InstallationResultToText = "Succeeded with errors"
        Case 4
            InstallationResultToText = "Failed"
        Case 5
            InstallationResultToText = "Cancelled"
        Case Else
            InstallationResultToText = "Unexpected (" & result & ")"
    End Select
End Function

Function DeploymentActionToText(action)
    Select Case action
        Case 0
            DeploymentActionToText = "None (Inherit)"
        Case 1
            DeploymentActionToText = "Installation"
        Case 2
            DeploymentActionToText = "Uninstallation"
        Case 3
            DeploymentActionToText = "Detection"
        Case 4
            DeploymentActionToText = "Optional Installation"
        Case Else
            DeploymentActionToText = "Unexpected (" & action & ")"
    End Select
End Function


Function UpdateDescription(update)
    Dim description
    Dim I
    Dim category
    description = update.Title & " {" & update.Identity.UpdateID & "." & update.Identity.RevisionNumber & "}"
    If update.IsHidden Then
        description = description & " (hidden)"
    End If
    If WScript.Arguments.Named.Exists("ShowDetails") Then
        if update.KBArticleIDs.Count > 0 Then
            description = description & " ("
            For I = 0 To update.KBArticleIDs.Count -1
                If I > 0 Then
                    description = description & ","
                End If
                description = description & "KB" & update.KBArticleIDs.Item(I)
            Next
            description = description & ")"
        End If
        description = description & " Categories: "
        For I = 0 to update.Categories.Count - 1
            Set category = update.Categories.Item(I)
            If I > 0 Then
                description = description & ","
            End If
            description = description & category.Name & " {" & category.CategoryID & "}"
        Next
        description = description & " Deployment action: " & DeploymentActionToText(update.DeploymentAction)
    End If
    UpdateDescription = description
End Function

Dim appName
If WScript.Arguments.Named.Exists("AppName") Then
    appName = WScript.Arguments.Named.Item("AppName")
Else
    appName = "WUA API Sample Script"
End If

Dim criteria
If WScript.Arguments.Named.Exists("Criteria") Then
    criteria = WScript.Arguments.Named.Item("Criteria")
Else
    criteria = "IsInstalled=0 and Type='Software' and IsHidden=0"
End If

Dim isAutomated
isAutomated = WScript.Arguments.Named.Exists("Automate")

Dim ignoreSupersedence
ignoreSupersedence = WScript.Arguments.Named.Exists("IgnoreSupersedence")

Dim showBundle
showBundle = WScript.Arguments.Named.Exists("ShowBundle")

Dim serverSelection
Dim serviceId
serverSelection = 0
serviceId = ""

If WScript.Arguments.Named.Exists("Service") Then
    Select Case UCase(WScript.Arguments.Named.Item("Service"))
        Case "WU"
            serverSelection = 2
        Case "MU"
            serverSelection = 3
            serviceId = "7971f918-a847-4430-9279-4a52d1efe18d"
        Case "WSUS"
            serverSelection = 1
        case "DCAT"
            serverSelection = 3
            serviceId = "855E8A7C-ECB4-4CA3-B045-1DFA50104289"
        case "STORE"
            serverSelection = 3
            serviceId = "117cab2d-82b1-4b5a-a08c-4d62dbee7782"
        Case Else
            serverSelection = 3
            serviceId = WScript.Arguments.Named.Item("Service")
    End Select
End If

Dim noDownload
noDownload = WScript.Arguments.Named.Exists("NoDownload")

Dim noInstall
noInstall = WScript.Arguments.Named.Exists("NoInstall")

Dim hide
hide = WScript.Arguments.Named.Exists("Hide")

Dim show
show = WScript.Arguments.Named.Exists("Show")

Dim strInput
strInput = ""

Dim returnValue
returnValue = 0

Dim automaticUpdates
Dim updateSettings
Dim objWMIService
Dim colListOfServices
Dim objService

Dim secondInstallPass
secondInstallPass = false

Dim updateSession
Set updateSession = CreateObject("Microsoft.Update.Session")
updateSession.ClientApplicationID = appName

Dim updateServiceManager
Dim offlineService
If WScript.Arguments.Named.Exists("Offline") Then
    Set updateServiceManager = CreateObject("Microsoft.Update.ServiceManager")
    Set offlineService = updateServiceManager.AddScanPackageService(appName, WScript.Arguments.Named.Item("Offline"), 0)
    serverSelection = 3
    serviceId = offlineService.ServiceID
    WScript.Echo "Registriertes offline scan cab, service ID " & serviceId & vbCRLF
End If
    
Dim updateSearcher
Set updateSearcher = updateSession.CreateUpdateSearcher()
updateSearcher.ServerSelection = serverSelection
If serverSelection = 3 Then
    updateSearcher.ServiceId = serviceId
End If
If ignoreSupersedence Then
    updateSearcher.IncludePotentiallySupersededUpdates = true
End If

WScript.Echo "Updates werden gesucht..." & vbCRLF

Dim searchResult
Set searchResult = updateSearcher.Search(criteria)

WScript.Echo "Liste geeigneter Updates auf dem Computer:"

Dim I
Dim B
For I = 0 To searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)
    WScript.Echo I + 1 & "> " & UpdateDescription(update)
    If showBundle Then
        For B = 0 to update.BundledUpdates.Count-1
            WScript.Echo I+1 & "> " & B+1 & "> " & UpdateDescription(update.BundledUpdates.Item(B))
        Next
    End If
Next

Dim updatesToDownload
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

If searchResult.Updates.Count = 0 Then
    WScript.Echo "Keine geeigneten Updates vorhanden."
Else
    WScript.Echo vbCRLF & "Suchergebnisse prüfen:"

    Dim update
    Dim description
    Dim addThisUpdate
    Dim hideThisUpdate
    Dim showThisUpdate
    Dim atLeastOneAdded
    Dim propertyTest
    atLeastOneAdded = false
    Dim exclusiveAdded
    exclusiveAdded = false
    If noDownload And Not hide And Not show Then
        WScript.Echo "Downloads wie gewünscht überspringen."
    Else
        For I = 0 to searchResult.Updates.Count-1
            Set update = searchResult.Updates.Item(I)
            description = UpdateDescription(update)
            addThisUpdate = false
            If hide And Not update.IsHidden Then
                strInput = "Y"
                If Not isAutomated Then
                    WScript.Echo I + 1 & "> : " & description  & _
                    " wird jetzt angezeigt; willst du es ausblenden? ([Y]/N)"
                    strInput = WScript.StdIn.Readline
                    WScript.Echo
                End If
                If (strInput = "Y" or strInput = "y") Then
                    WScript.Echo "Update ausblenden"
                    update.IsHidden = true
                End If
            ElseIf show And update.IsHidden Then
                strInput = "Y"
                If Not isAutomated Then
                    WScript.Echo I + 1 & "> : " & description  & _
                    " ist jetzt ausgeblendet; willst du es anzeigen? ([Y]/N)"
                    strInput = WScript.StdIn.Readline
                    WScript.Echo
                End If
                If (strInput = "Y" or strInput = "y") Then
                    WScript.Echo "Update anzeigen?"
                    update.IsHidden = false
                End If
            End If
                
            If exclusiveAdded Then
                WScript.Echo I + 1 & "> skipping: " & description & _
                    " weil bereits ein exklusives Update ausgewählt wurde"
            ElseIf Not noDownload Then
                propertyTest = false
                On Error Resume Next
                propertyTest = update.InstallationBehavior.CanRequestUserInput
                On Error GoTo 0
                If propertyTest = true Then
                    WScript.Echo I + 1 & "> überspringen: " & description  & _
                    " weil es eine Benutzereingabe erfordert"
                Else
                    propertyTest = true
                    On Error Resume Next
                    propertyTest = update.EulaAccepted
                    On Error GoTo 0
                    If propertyTest = false Then
                        If isAutomated Then
                            WScript.Echo I + 1 & "> überspringen: " & description  & _
                            " weil es eine Lizenzvereinbarung gibt, die nicht akzeptiert wurde"
                        Else
                            WScript.Echo I + 1 & "> note: " & description  & _
                            " hat eine Lizenzvereinbarung, die akzeptiert werden muss:"
                            WScript.Echo update.EulaText
                            WScript.Echo "Akzeptieren Sie diese Lizenzvereinbarung? (Y/[N])"
                            strInput = WScript.StdIn.Readline
                            WScript.Echo 
                            If (strInput = "Y" or strInput = "y") Then
                                update.AcceptEula()
                                addThisUpdate = true
                            Else
                                WScript.Echo I + 1 & "> skipping: " & description  & _
                                " weil die Lizenzvereinbarung abgelehnt wurde"
                            End If
                        End If
                    Else
                        addThisUpdate = true
                    End If
                End If
                If addThisUpdate Then
                    propertyTest = 0
                    On Error Resume Next
                    propertyTest = update.InstallationBehavior.Impact
                    On Error GoTo 0
                    If propertyTest = 2 Then
                        If atLeastOneAdded Then
                            WScript.Echo I + 1 & "> skipping: " & description  & _
                            " weil es exklusiv ist und andere Updates zuerst installiert werden"
                            addThisUpdate = false
                        End If
                    End If
                End If
                If addThisUpdate Then
                    If Not isAutomated Then
                        WScript.Echo I + 1 & "> : " & description  & _
                        " ist anwendbar; Möchten Sie es installieren? ([Y]/N)"
                        strInput = WScript.StdIn.Readline
                        WScript.Echo
                        If (strInput = "N" or strInput = "n") Then
                            WScript.Echo "Update überspringen"
                            addThisUpdate = false
                       End If
                    End If
                End If
                If addThisUpdate Then
                    WScript.Echo I + 1 & "> adding: " & description  
                    updatesToDownload.Add(update)
                    atLeastOneAdded = true
                    On Error Resume Next
                    propertyTest = update.InstallationBehavior.Impact
                    On Error GoTo 0
                    If propertyTest = 2 Then
                        WScript.Echo "Dieses Update ist exklusiv; Überspringe verbleibende Updates"
                        exclusiveAdded = true
                    End If
                End If
            End If
        Next
    End If
End If

Dim updatesToInstall
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

Dim rebootMayBeRequired
rebootMayBeRequired = false

If (Not noDownload) And (updatesToDownload.Count > 0) Then
    WScript.Echo vbCRLF & "Updates herunterladen..."

    Dim downloader
    Set downloader = updateSession.CreateUpdateDownloader() 
    downloader.Updates = updatesToDownload
    downloader.Download()

    WScript.Echo vbCRLF & "Updates erfolgreich heruntergeladen:"

    For I = 0 To updatesToDownload.Count-1
        Set update = updatesToDownload.Item(I)
        If update.IsDownloaded = true Then
            WScript.Echo I + 1 & "> " & UpdateDescription(update) 
            updatesToInstall.Add(update) 
            propertyTest = 0
            On Error Resume Next
            propertyTest = update.InstallationBehavior.RebootBehavior
            On Error GoTo 0
            If propertyTest > 0 Then
                rebootMayBeRequired = true
            End If
        End If
    Next
End If

strInput = "N"
If noInstall Then
    WScript.Echo "Installation wie gewünscht überspringen."
Else
    If updatesToInstall.Count > 0 Then
        strInput = "Y"
        If rebootMayBeRequired = true Then
            WScript.Echo vbCRLF & "Diese Updates erfordern möglicherweise einen Neustart."
        End If
        If Not isAutomated Then
            WScript.Echo  vbCRLF & "Möchten Sie jetzt Updates installieren? (Y/[N])"
            strInput = WScript.StdIn.Readline
            WScript.Echo 
        End If
    End If

    If (strInput = "Y" or strInput = "y") Then
        WScript.Echo "Installiere Updates..."
        Dim installer
        Set installer = updateSession.CreateUpdateInstaller()
        installer.Updates = updatesToInstall
        Dim installationResult
        Set installationResult = installer.Install()
 
        returnValue = 1
        'Output results of install
        WScript.Echo "Installationsergebnis: " & _
        InstallationResultToText(installationResult.ResultCode) 
        WScript.Echo "Neustart erforderlich: " & _ 
        installationResult.RebootRequired & vbCRLF 
        WScript.Echo "Auflistung der installierten Updates " & _
        "and individual installation results:" 
 
        For I = 0 to updatesToInstall.Count - 1
            WScript.Echo I + 1 & "> " & _
            UpdateDescription(updatesToInstall.Item(i)) & ": " & _
            InstallationResultToText(installationResult.GetUpdateResult(I).ResultCode) & _
            " HRESULT: " & installationResult.GetUpdateResult(I).HResult
            If installationResult.GetUpdateResult(I).HResult = -2145116147 Then
                WScript.Echo "Für ein Update waren zusätzliche heruntergeladene Inhalte erforderlich. Bitte führen Sie das Skript erneut aus."
            End If
        Next
       
        If installationResult.RebootRequired And WScript.Arguments.Named.Exists("RebootToComplete") Then
            strInput = "Y"
            If Not isAutomated Then
                WScript.Echo  vbCRLF & "Möchten Sie jetzt einen Neustart durchführen, um die Installation abzuschließen? (Y/[N])"
                strInput = WScript.StdIn.Readline
                WScript.Echo 
            End If
            If (strInput = "Y" or strInput = "y") Then
                WScript.Echo "Installation durchführen..." & vbCRLF
                installer.Commit(0)
                WScript.Echo "Neustart in 30 Sekunden auslösen..." & vbCRLF
                Dim oShell
                Set oShell = WScript.CreateObject("WScript.Shell")
                oShell.Run "shutdown /r /t 30", 1
            End If     
        End If
    End If
End If

WScript.Quit (returnValue)

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von Holgi » 26.04.2024, 11:09

Yep, so sollte es sein.
womit wir jetzt bei meiner Frage angelangt sind:
viewtopic.php?t=31766#p427080
werden wirklich auch alle Updates gefunden und installiert (z.B. auch KB890830)?
Kann das bei mir nicht testen, da alles bereits auf dem neuesten Stand.

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von g-force » 26.04.2024, 10:42

Es kommen zwar Abfragen, aber das Script läuft ohne Eingabe durch.

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von Holgi » 26.04.2024, 09:56

g-force hat geschrieben: 26.04.2024, 09:34 Aha, das hatte ich übersehen. Ich habe von VBS-Scripten leider auch (noch) keinen Schimmer.
kannst du es dennoch testen und mir Rückmeldung geben?
Eingabeaufforderung:

Code: Alles auswählen

c:\Windows\System32\cscript.exe "Pfad zur vbs"\WUA_SearchDownloadInstall.vbs"
die letzte, die ich hier gepostet habe (nicht die erste!)

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von g-force » 26.04.2024, 09:34

Aha, das hatte ich übersehen. Ich habe von VBS-Scripten leider auch (noch) keinen Schimmer.

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von Holgi » 26.04.2024, 09:14

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.

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von Holgi » 25.04.2024, 22:51

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

von g-force » 25.04.2024, 20:36

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

von g-force » 25.04.2024, 20:33

Holgi_1.PNG
Holgi_2.PNG
Holgi_3.PNG
Holgi_4.PNG

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von Holgi » 25.04.2024, 14:31

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

von Holgi » 23.04.2024, 13:37

Hatte ich auch schon gedacht.

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von g-force » 23.04.2024, 13:31

Hast Du mal "ChatGP" für sowas bemüht?

Re: benötige Hilfe bei einem VisualBasic (*.VBS) Windows Update Script

von Holgi » 22.04.2024, 22:17

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

von Holgi » 22.04.2024, 17:33

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.

Nach oben