Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > accessing WMI object's attributes

Reply
Thread Tools

accessing WMI object's attributes

 
 
Martin
Guest
Posts: n/a
 
      03-11-2005
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
 
Reply With Quote
 
 
 
 
Thomas Kratz
Guest
Posts: n/a
 
      03-11-2005
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^.-
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WebControl.Attributes.Add and custom attributes P4trykx ASP .Net 2 01-31-2007 04:33 PM
Parse reserved attributes as normal attributes Max XML 1 09-22-2006 12:04 PM
"Automation server can't create Objects" error while accessing the WMI scripts from Linux box drk.kumar@gmail.com Javascript 1 07-21-2006 05:24 PM
Accessing WMI Service and Scanning Subnets via an Applet DartmanX Java 1 04-07-2006 08:45 PM
Accessing Windows WMI Info from Unix John Ramsden Perl Misc 0 05-11-2004 01:46 PM



Advertisments