Home: Perl Programming Help: Win32 Programming Help:
Win32_Processor and remote Load Percentage?



jhyland87
Novice

Mar 16, 2010, 5:07 PM


Views: 7702
Win32_Processor and remote Load Percentage?

So im trying to execute this from my local work station, and I cant seem to find anything wrong with it, it should work, as far as I can tell.

All it does is go into a remote server, and get the LoadPercentage out of the Win32_Processor object


Quote
use 5.006;

use Win32::OLE;
use Win32::OLE::Variant;

$server = "xxx.xxx.xxx.xxx";
$username = "administrator";
$password = 'xxxxxxxxxxxxx';




$locator = Win32::OLE-> new("WbemScripting.SWbemLocator")or die "Can't access WMI on local machine.", Win32::OLE-> LastError;
$serverConn = $locator-> ConnectServer($server, "root/CIMV2", $username, $password) or die "Can't access WMI on remote machine $server: ", Win32::OLE-> LastError;

$colItems = $serverConn-> Get( "Win32_Processor" ) || die "Error: ".Win32::OLE-> LastError();


print "LoadPercentage: ". $colItems->{LoadPercentage} ."\n";


It just returns "Load Percentage: "

Any idea at all?


(This post was edited by jhyland87 on Mar 16, 2010, 5:07 PM)


FishMonger
Veteran / Moderator

Mar 16, 2010, 8:00 PM


Views: 7691
Re: [jhyland87] Win32_Processor and remote Load Percentage?

I do very little Windows specific scripting and I've never used the Win32::OLE module, but the first step I'd take would be to use Data::Dumper to dump the $colItems object.

Actually, that would be my second step. The first step would be to add the warnings and strict pragmas and fix the problems that they point out.


jhyland87
Novice

Mar 17, 2010, 2:23 PM


Views: 7678
Re: [FishMonger] Win32_Processor and remote Load Percentage?

Good idea on the dumper, didnt use that. Ive changed my code to


Code
use 5.006; 
use warnings;
use strict;
use Win32::OLE;
use Win32::OLE::Variant;
use Data::Dumper;

my $server = "xx.xx.xx.xx";
my $username = "administrator";
my $password = 'xxxxxxxxxxxx';




my $locator = Win32::OLE-> new("WbemScripting.SWbemLocator")or die "Can't access WMI on local machine.", Win32::OLE-> LastError;
my $serverConn = $locator-> ConnectServer($server, "root/CIMV2", $username, $password) or die "Can't access WMI on remote machine $server: ", Win32::OLE-> LastError;

my $colItems = $serverConn-> Get( "Win32_Processor" ) || die "Error: ".Win32::OLE-> LastError();

print Dumper($colItems);


Which returns..


Quote
$VAR1 = bless( {
'Qualifiers_' => bless( {
'Count' => 4
}, 'Win32::OLE' ),
'Properties_' => bless( {
'Count' => 44
}, 'Win32::OLE' ),
'Methods_' => bless( {
'Count' => 2
}, 'Win32::OLE' ),
'Derivation_' => [
'CIM_Processor',
'CIM_LogicalDevice',
'CIM_LogicalElement',
'CIM_ManagedSystemElement'
],
'Path_' => bless( {
'Path' => '\\\\xxxxx\\ROOT\\CIMV2:Win32_Processor',
'RelPath' => 'Win32_Processor',
'Server' => 'xxxxx',
'Namespace' => 'ROOT\\CIMV2',
'ParentNamespace' => 'ROOT',
'DisplayName' => 'WINMGMTS:{authenticationLevel=pkt,impersonationLevel=impersonate}!\\\\XXXXX\\ROOT\\CIMV2:Win32_Processor',
'Class' => 'Win32_Processor',
'IsClass' => 1,
'IsSingleton' => 0,
'Keys' => bless( {
'Count' => 0
}, 'Win32::OLE' ),
'Security_' => bless( {
'ImpersonationLevel' => 3,
'AuthenticationLevel' => 4,
'Privileges' => bless( {
'Count' => 0
}, 'Win32::OLE' )
}, 'Win32::OLE' ),
'Locale' => '',
'Authority' => ''
}, 'Win32::OLE' ),
'Security_' => bless( {
'ImpersonationLevel' => 3,
'AuthenticationLevel' => 4,
'Privileges' => bless( {
'Count' => 0
}, 'Win32::OLE' )
}, 'Win32::OLE' ),
'SystemProperties_' => bless( {
'Count' => 10
}, 'Win32::OLE' )
}, 'Win32::OLE' );


Oddly enough, none of that actually has any information about the processor... interesting. Totally different than whats ran locally