Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 963 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows update downloader.Download() fail

#1
I come across a sample vbscript program from Microsoft site regarding Windows Update(named WUA_SearchDownloadInstall.vbs).

[To see links please register here]


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

WScript.Echo "Searching for updates..." & vbCRLF

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)
WScript.Echo I + 1 & "> adding: " & update.Title
updatesToDownload.Add(update)
Next

WScript.Echo vbCRLF & "Downloading updates..."

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

WScript.Echo vbCRLF & "List of downloaded updates:"

For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded Then
WScript.Echo I + 1 & "> " & update.Title
End If
Next

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

WScript.Echo vbCRLF & _
"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
WScript.Echo I + 1 & "> adding: " & update.Title
updatesToInstall.Add(update)
End If
Next

WScript.Echo vbCRLF & "Would you like to install updates now? (Y/N)"
strInput = WScript.StdIn.Readline
WScript.Echo

If (strInput = "N" or strInput = "n") Then
WScript.Quit
ElseIf (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



**his script runs well until it reaches**

downloader.Download()

On that line, the CMD window outputs

C:\wu-install\WUA_SearchDownloadInstall.vbs(37, 1) (null): 0x80240044


By adding a printf line before `downloader.Download()` , I can see that the error is asserted immediately in Download().

My question is: How can I find clue to know the error reason? May be there is way to catch the exception and let output some detailed error message.

I tried with the help of this post(

[To see links please register here]

), and write around the problem line:

On Error Resume Next
downloader.Download()
If Err.Number <> 0 Then
WScript.Echo Err.Description
WScript.Quit 4
End If
On Error Goto 0


But `WScript.Echo Err.Description` outputs nothing. How can I do?

![enter image description here][1]

My environment: Windows 7 32-bit.


[[[ UPDATE ]]]

I'm back on this question. I've updated my script to use JScript. Yes, it is convenient than VBScript.

Now I have such code snippet:

var downloader = updsession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
try {
downloader.Download()
}
catch(err) {
WScript.Echo("Oops, Download error.")
WScript.Echo("Possible reason:")
WScript.Echo("* On Windows Vista/7, This requires you Run as Administrator.")
WScript.Quit(3)
}

Remaining question is: How do I get error code from Download() so that I can check error reason. The page at

[To see links please register here]

seems too coarse for me to find the answer.

Waiting for your help again. Thank you.

[1]:
Reply

#2
You are receiving this error because the Windows Updater API requires elevated priveleges. Launching your script in an elevated command prompt should solve the issue.

As a side note, you should make sure that you are connected to the internet, the Windows Update service is enabled, and that there are no pending update installations (i.e. waiting to install at shutdown). These things will also cause errors.

[edit]

You should be able to retrieve the status from inside the the library. The `Download` method returns a [status code][1]. Assigning its result to a variable may prevent your script from bombing out. If not, try using `On Error Goto Next` to get around it. You can find the various result codes and error codes below.

[Windows Update Agent Result Codes][2]

[WUA Networking Error Codes][3]

[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through