Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Error Resume Next not working on GetObject WMI

Status
Not open for further replies.

humbletech99

Programmer
Nov 22, 2005
155
GB
I have a script with the following code block:
Code:
...
Err.Clear
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strServer & "\root\CIMV2")
If Err.Number Then
    <QUIT GRACEFULLY>
End If
...
However, when I run it where strServer = nonExistantMachine I get a complete lack of error handling:
Code:
(290, 14) Microsoft VBScript runtime error: The remote server machine does not exist or is unavailable
Why is this occurring if I have told it to continue on error so that I can handle it myself?
 
You may need to post more code for the <QUIT GRACEFULLY> section.
 
It literally does a wscript.echo "something" and then a wscript.quit customExitCode.

The line number error shown 290 is the exact line number of the GetObject call for WMI.

So the VBS runtime error is really bailing out on the getobject call, ignoring the on error resume next than immediately preceeds it.
 
When I paste the code you show into a file, it <QUITs GRACEFULLY>, which is why I wondered if the problem could be elsewhere.
 
yes I found out that when I run this against a real server it works and even when I run it against a fake name it handles the error correctly and is caused and outputs properly.

However, I am running this on a server against my workstation. I shut off the wmi service and then started it again and ever since then it only fails in this way when trying to query wmi on my workstation.

If I query any other machine it behaves properly.

I'm a bit confused as to what I have done on my workstation...
 
Thanks for the link. In the "Can't connect to remote computer" section I have been through the checklist and the only thing could be the firewall, but then shouldn't it still be caught by the on error resume next?

I am running this as a domain admin, the wmi is compatible since it worked a couple of hours ago, and the computer is online.
 
The sketch shown should differ from the real script run in some essential way (such as the getobject line is in some sub being called and that the sub does not contain its own "on error resume next" statement). Why it is shown to the forum the way it is posted is beyond me, but, one cannot debug something imaginary: that's a waste of time.
 
I copied and pasted the code exactly from my script, just stripped out a couple of wscript.echo lines and wscript.quit.

The error catching works, even when querying non existent machines and other real servers but not when querying my workstation. Read 2 posts up...
 
First, any time I make a WMI connection I always test to see if the workstation is valid with a ping test...this will save time. Second, if your script works locally on the workstation but not remotely...do you have a firewall enabled, have you checked DCOM (if enabled and proper security settings), have you attempted to connect using wbemtest?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
wbem test does not connect. In fact the firewall was restarted when I restarted the wmi service...

wbemtest gave me the rpc server is unavailable. I'll have to double check gpo settings on the firewall since it doesn't show remote management in the local firewall.

although I agree with the ping idea, xp sp2 disables ping by default in the firewall and even if it doesn't some people do disable ping. It's better to just do the check, because ping could be blocked but the host and the port required could be up/open.
 
It is quasi impossible that the runtime error message is triggered from any of the statements within the block where "on error resume next" rules. The script must be error out at the place where it does not rule. Hence, it must not be pointing to the getobject() immediately under the "on error" directive. Otherwise, you have to report to microsoft and get your recognition from them.
 
Hmm, I'm not after recognition, I know this is broken. But what can I do...? I have checked and double checked this...
 
Let me get this straight...

Running script on server against server works
but
Running script on server against pc doesn't work

What happens when you run it on the pc against itself?
or
Script on server against another server?

I've tried all sorts of things to reproduce your results, but I can't when "On Error Resume Next" is present.

Based on the posts, you've got other problems with client connectivity, but the error you're recieving doesn't make sense.


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Yes I know this is strange, gave up trying to fix it since it wasn't that important and the servers I was actually working with still worked...

Basically, it could query other servers, but not this workstation... but it could query other workstations...

I think I did something funny to the workstation when I was fiddling the service on and off for error testing, it only started doing this after I put it down and back up. Running it locally on the workstation worked...

ps. Like the sig...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top