John Serink wrote:
> Use this as a hack template till you get your head around it:
> #!perl
>
> # Simple Perl Script to illustrate use of WMI to gather system
> information
> # and display it in the same format at the Windows Management Console
...
You can do a more generic dump of the object like this (handles
arrays as well as scalar values) :
use strict;
use warnings;
use Win32::OLE('in');
$| = 1;
# Usage: script [nodename [class]]
my $computer = shift || Win32::NodeName;
my $class = shift || 'Win32_Battery';
my $base_class = "winmgmts:\\\\$computer\\root\\CIMV2";
my $objWMIService = Win32::OLE->GetObject($base_class) or
die "GetObject: $! ($^E)";
use constant ReturnImmed => 0x10;
use constant ForwardOnly => 0x20;
my $items = $objWMIService->ExecQuery("SELECT * FROM $class", 'WQL',
ReturnImmed | ForwardOnly);
print "$class:\n"; dump_items ($items);
exit;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub dump_items {
my $items = shift;
foreach my $node (in $items) {
my @objs = (Win32::OLE::Enum->All($node->{Properties_}));
foreach my $obj (sort { $a->{Name} cmp $b->{Name} } @objs) {
my $name = $obj->{Name};
if (ref ($obj->{Value}) eq "ARRAY") {
my $vals = $obj->{Value};
print " $name = {";
my $first = 0;
foreach my $value (@$vals) {
print ", " if $first++;
if (not defined $value) {
print '<undef>';
} else {
print "'$value'";
}
}
print "}\n";
} else {
my $value = $obj->{Value};
if (not defined $value) {
print " $name = <undef>\n";
} else {
print " $name = '$value'\n";
}
}
}
}
}
__END__
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs