accessing WMI object's attributes

M

Martin

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.

I also tried dereferencing:

my $pwins = ${$objItem->{WINSPrimaryServer}};

but the result is the same.

Using

print Dumper $objItem1;

I get something like:

$VAR1 = bless( {
'Qualifiers_' => bless( {
'Count' => 4
}, 'Win32::OLE' ),
'Properties_' => bless( {
'Count' => 61
}, 'Win32::OLE' ),
'Methods_' => bless( {
'Count' => 41
}, 'Win32::OLE' ),
'Derivation_' => [
'CIM_Setting'
],
'Path_' => bless( {
.........

But I can't find the desired attribute.


Does anybody have an idea, what's going wrong.

Thank,
Martin
 
T

Thomas Kratz

Martin said:
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^.-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top