Martin wrote:
> Hi all,
>
> I'm pretty new to perl and toying around with WMI. Now I stumble upon
> accessing the attributes of an WMI object.
>
> The problem is as follows:
>
> I've an object reference to Win32_NetworkAdapterConfiguration called
> $objItem.
>
> If I say
>
> print "$objItem->{WINSPrimaryServer}\n";
>
> I get the desired output. But if I say
>
> my $pwins = $objItem->{WINSPrimaryServer};
> print "$pwins\n";
>
> I don't get any output.
[rest snipped]
Next time please show real code we can run. Have a look a the posting
guidelines posted to this group regularly.
Here's an example script to get at the WINS primary address. Please note
that I am using accessor methods to get at the values like:
$nwa->WINSPrimaryServer instead of accessing the value directly via
$nwa->{WINSPrimaryServer}. Not that this makes any difference. I couldn't
see the behaviour you describe. But without real code I can't tell you more.
use strict;
use warnings;
use Win32::OLE qw/in/;
Win32::OLE->Option(Warn => 1);
my $wmi = Win32::OLE->GetObject(
"winmgmts:{impersonationLevel=impersonate}\\root\\ cimv2"
) or die "error initializing WMI interface", Win32::OLE->LastError;
printf "%-30s %s\n", 'IP-Addresses', 'WINS Primary';
for my $nwa ( in($wmi->InstancesOf('Win32_NetworkAdapterConfiguration' )) ) {
next unless $nwa->IPEnabled;
my $ip = join(',', @{$nwa->IPAddress});
my $wins = $nwa->WINSPrimaryServer || 'not configured';
printf "%-30s %s\n", $ip, $wins;
}
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-
|