Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

How do I get past "WMI Connection failed" errors

by StarkRavingCalm (Sexton)
on Feb 12, 2009 at 19:10 UTC ( #743434=perlquestion: print w/replies, xml ) Need Help??
StarkRavingCalm has asked for the wisdom of the Perl Monks concerning the following question:

Hoping this is an easy one...

I have a script that I am using to query Windows machines for Hotfixes. I am running it as domain admin. When it connects to a machine, I get the data I am looking for. But, if it hits a machine that is down (I verify with a ping), I get "WMI Connection failed" errors and then it stops. I have a warn statement in there but it does not continue.

Here is the relevant data in the script.(The script itself is HUGE as it does some munging at the end before it writes to a file)

my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\ro +ot\\CIMV2") or warn "WMI connection failed.\n"; my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Quick +FixEngineering", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);

Can anyone help me get past these errors?

Replies are listed 'Best First'.
Re: How do I get past "WMI Connection failed" errors
by Corion (Pope) on Feb 12, 2009 at 19:15 UTC

    Most likely you can catch the error using an eval block. Otherwise, I'd just ping the machine before trying to connect to it:

    select responsetime from Win32_PingStatus where Address = ''

      That could work as a temporary work around.

      Right now I am reading each machine name from an array, but I ultimately want reading each server in real time from the domain.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://743434]
Approved by Corion
[1nickt]: Discipulus Yes, I think it is maybe easier to be a good monk in "real" life when you are young and idealistic or old and weary ... nost so much in middle age.
[1nickt]: 😲 ... or did you mean the Middle Ages, when monastic life was more, umm, "earthy" ?!

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-12-13 14:05 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (368 votes). Check out past polls.