I've got some code to connect to remote machines via WMI. I need to build in some error handling if the machine is down/unavailable etc.
The problem is that the "if err.number" part of the code is not being executed when an error occures, the script just trundles on. If I remove "on error resume next" then I just get the error message. Can anyone help?
The error I'm expecting is this:
Script: c:\blah\somscript.vbs
Line: 106
Char: 1
Error: The remote server machine does not exist or is unavailable: 'GetObject'
Code: 800A01CE
Source; microsoft VBScript runtime error
If I change the "if err.number" line to:
I just get an error about "expected 'then'" statement on that line.
Help!
The problem is that the "if err.number" part of the code is not being executed when an error occures, the script just trundles on. If I remove "on error resume next" then I just get the error message. Can anyone help?
Code:
on error resume next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComp1 & "\root\cimv2")
If Err.Number <> 0 then
wscript.echo Err.Number
wscript.quit
The error I'm expecting is this:
Script: c:\blah\somscript.vbs
Line: 106
Char: 1
Error: The remote server machine does not exist or is unavailable: 'GetObject'
Code: 800A01CE
Source; microsoft VBScript runtime error
If I change the "if err.number" line to:
Code:
if err.number = 800A01CE then
I just get an error about "expected 'then'" statement on that line.
Help!