Eric Hennessey wrote:
I'm using WMI calls to enumerate network adapters and display them. In
the WMI docs, the property IPAddress is an array value in
Win32_NetWorkAdapterConfiguration.
So why does the following produce ARRAY(0xsomehexvalue) for its output?
my @ipaddrs = $adapter->{'IPAddress'};
.
.
.
foreach my $ipaddr (@ipaddrs) {
print "$ipaddr\n";
}
Example script to get property that handles array refs:
Call: perl getWMIprop.pl Win32_NetworkAdapterConfiguration IPAddress
#!perl -w --
use strict;
use Win32::OLE qw(in);
die "\nUsage: $0 <class> <property>\n\n" if @ARGV < 2;
my $Win32_Class = $ARGV[0];
my $Property = $ARGV[1];
my $mach = Win32::NodeName;
my $Class = "WinMgmts:\\\\$mach";
my $WMI = Win32::OLE->GetObject ($Class);
my $objs = $WMI->ExecQuery("SELECT * FROM $Win32_Class");
if (scalar (in $objs) < 1) {
print "Class returned no objects\n";
exit;
}
foreach my $node (in $objs) {
my @objs = (Win32::OLE::Enum->All($node->{Properties_}));
foreach my $obj (@objs) { # $obj is hashref
next if $obj->{Name} ne $Property;
our $oref;
eval { $oref = ref $obj->{Value}; };
next if not defined $oref;
if (ref ($obj->{Value}) eq "ARRAY") {
my $vals = $obj->{Value};
print scalar @$vals, " values\n" if $debug;
print " $obj->{Name} = {";
my $first = 1;
foreach my $value (@$vals) {
if ($first) {
$first = 0;
} else {
print ", ";
}
if (defined $value) {
print "$value";
} else {
print "undef";
}
}
print "}\n";
} else {
print " $obj->{Name} = ";
if (defined $obj->{Value}) {
print "$obj->{Value}\n";
} else {
print "undef\n";
}
}
}
}
exit;
--
,-/- __ _ _ $Bill Luebkert ICQ=162126130
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs