Je suis tombé sur un exemple de programme vbscript du site Microsoft concernant Windows Update (nommé WUA_SearchDownloadInstall.vbs).Windows update downloader.Download() échoue
http://msdn.microsoft.com/en-us/library/aa387102%28VS.85%29.aspx
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
son script fonctionne bien jusqu'à ce qu'il atteigne
downloader.Download()
Sur cette ligne, les sorties de la fenêtre CMD
C:\wu-install\WUA_SearchDownloadInstall.vbs(37, 1) (null): 0x80240044
En ajoutant une ligne de printf avant downloader.Download()
, Je peux voir que L'erreur est affirmée immédiatement dans Download().
Ma question est: Comment puis-je trouver des indices pour connaître la raison de l'erreur? Peut être il y a moyen d'attraper l'exception et laisser sortir un message d'erreur détaillé.
J'ai essayé avec l'aide de ce post (Seem like a VBscript exception, how to cope with?), et écrire autour de la ligne de problème:
On Error Resume Next
downloader.Download()
If Err.Number <> 0 Then
WScript.Echo Err.Description
WScript.Quit 4
End If
On Error Goto 0
Mais rien WScript.Echo Err.Description
sorties. Comment puis-je faire?
Mon environnement: Windows 7 32 bits.
[[[UPDATE]]]
Je suis de retour sur cette question. J'ai mis à jour mon script pour utiliser JScript. Oui, c'est pratique par rapport à VBScript.
Maintenant, j'ai extrait de ce code:
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)
}
restant question est: Comment puis-je obtenir le code d'erreur Télécharger() afin que je puisse vérifier raison d'erreur. La page au http://msdn.microsoft.com/en-us/library/windows/desktop/aa386134%28v=vs.85%29.aspx me semble trop grossière pour trouver la réponse.
En attente de votre aide à nouveau. Je vous remercie.
Je vous recommande fortement de commencer une nouvelle question au lieu de modifier celui-ci. Votre question initiale a déjà été traitée. Vous pouvez inclure un lien vers cette question en tant qu'information de base. –