I’m trying an example from M$ site regarding calling Windows Update programatically.
'http://msdn.microsoft.com/en-us/library/aa387102%28VS.85%29.aspx
'http://msdn.microsoft.com/en-us/library/aa386526%28v=vs.85%29.aspx
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
WScript.Echo "Searching for updates..." & vbCRLF
Set searchResult = updateSearcher.Search("IsInstalled=1 and Type='Software'")
On executing the last line, if your network is broken, I’ll see on CMD window:
C:\wu-script\wu-install.vbs(9, 1) (null): 0x8024001F
It seems like updateSearcher.Search throws an exception and the whole script exits. How to catch this exception?
I’m not very familiar with VBScript. Please provide a quick hint or a reference URL.
You should use
On Errorstatement to handling VBScript errors.As you can see, catching error is too troublesome in VBScript. However, could also use javascript and its try-catch.
A sample WSF package based on the script that you gave.
wu-install.wsf
Runing with the cmd: