accessing WMI object's attributes

Discussion in 'Perl Misc' started by Martin, Mar 11, 2005.

  1. Martin

    Martin Guest

    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
     
    Martin, Mar 11, 2005
    #1
    1. Advertising

  2. Martin

    Thomas Kratz Guest

    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^.-
     
    Thomas Kratz, Mar 11, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DartmanX
    Replies:
    1
    Views:
    2,083
    Roedy Green
    Apr 7, 2006
  2. Max
    Replies:
    1
    Views:
    515
    Joe Kesselman
    Sep 22, 2006
  3. News123
    Replies:
    1
    Views:
    357
    Tim Golden
    Apr 16, 2010
  4. John Ramsden

    Accessing Windows WMI Info from Unix

    John Ramsden, May 11, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    149
    John Ramsden
    May 11, 2004
  5. Replies:
    1
    Views:
    281
Loading...

Share This Page