Vbscript 通过vbs更新Windows

Vbscript 通过vbs更新Windows,vbscript,windows-update,Vbscript,Windows Update,我记不起我在哪里找到的代码,但它曾经工作得很好。我没有以任何方式编辑过它,也不知道为什么它不再有效。我必须安装恢复磁盘,并希望它再次运行 'ServerSelection values ssDefault = 0 ssManagedServer = 1 ssWindowsUpdate = 2 ssOthers = 3 'InStr values intSearchStartChar = 1 Dim strTitle Set updateSession = CreateObje

我记不起我在哪里找到的代码,但它曾经工作得很好。我没有以任何方式编辑过它,也不知道为什么它不再有效。我必须安装恢复磁盘,并希望它再次运行

'ServerSelection values
ssDefault = 0
ssManagedServer = 1
ssWindowsUpdate = 2
ssOthers        = 3

'InStr values
intSearchStartChar = 1

Dim strTitle

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

updateSearcher.ServerSelection = ssWindowsUpdate
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")

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..."

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)"
''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
当我运行它时,它会给我一个更新列表,我可以选择下载和安装,但最后我得到一个错误

行:77字符:1
错误:0x80240044
代码:80240044
来源:(空)

试图用谷歌搜索


有人觉得这很熟悉吗?任何人有幸让它运行吗?

错误0x80240044转化为
WU_E_PER_MACHINE\u UPDATE\u ACCESS\u DENIED
-只有管理员才能对每台机器更新执行此操作。您是否尝试以管理员身份运行vbscript?是的,我以管理员身份运行,结果相同。