Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Using WMI in Perl

by rscott212 (Sexton)
on Mar 10, 2002 at 03:26 UTC ( [id://150657]=perlquestion: print w/replies, xml ) Need Help??

rscott212 has asked for the wisdom of the Perl Monks concerning the following question:

Need help! I found this script below in a book that uses the call to WMI::OLE. This checks the services on a machine and reports the status of the service. When I ran this script, it reported that the services that is stopped as running and the one's that is running as not running. Is there a special character that represents a null value in perl? Please take a look at this script and tell me what I need to do in order for this script to give me correct information.

<code> use Win32::OLE;

my $refWMI = Win32::OLE->GetObject("winMgmts:");
my $colServices = $refWMI->InstancesOf("Win32_Service");

foreach $refService(in $colServices){
print $refService->{Name}
. " is "
. ($refService->{Started} ? "not " : "")
. "running\n";
}

undef $colServices;
undef $refWMI;
<\code>

Replies are listed 'Best First'.
Re: Using WMI in Perl
by PrakashK (Pilgrim) on Mar 10, 2002 at 04:41 UTC
    Check your print statement. You're printing "not running" when the value of $refService->{Started} is true.

    Shouldn't it be like this?

    print $refService->{Name} . " is " . ($refService->{Started} ? "" : "not ") . "running\n";
    /prakash

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://150657]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found