secret has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I'm not very good at windows object and i encounter a problem when using Win32::OLE .

Here is what i do:

use Win32::OLE qw (in); my $Computer="."; my $WMIServices= Win32::OLE->GetObject("winmgmts:\\\\" . $Computer . " +\\root\\cimv2"); my $test=SubclassesOf $WMIServices; use Data::Dumper; print Dumper($test);
This gives the following result :
$VAR1 = bless( {
                 'Count' => 626,
                 'Security_' => bless( {
                                         'ImpersonationLevel' => 3,
                                         'AuthenticationLevel' => 6,
                                         'Privileges' => bless( {
                                                                  'Count' => 0
                                                                }, 'Win32::OLE' )
                                       }, 'Win32::OLE' )
               }, 'Win32::OLE' );

The problem is that when i look at the properties of $test with the Visual Basic Espions I see a whole lot of other objects, named "Item 1" to "Item 256" . Here's what i do in VB :

Set test = objWMIService.SubclassesOf()
My question is what are those Item objects and why am i not seeing them with Perl ?

Thanks for your explanations :)

Replies are listed 'Best First'.
Re: WMI SubclassesOf $WMIServices not giving all the objects ?
by BrowserUk (Patriarch) on Jan 23, 2006 at 12:03 UTC

    The return from SubclassesOf is a collection. To acess the members of the collection, use the in keyword, which you are importing with your

    use Win32::OLE qw (in);
    , in conjunction with a for loop.
    #! perl -slw use strict; use Win32::OLE qw (in); use Data::Dumper; my $Computer = "."; my $WMIServices = Win32::OLE->GetObject("winmgmts:\\\\" . $Computer . +"\\root\\cimv2"); my $test = $WMIServices->SubclassesOf; for my $sub ( in $test ) { print Dumper $sub; }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: WMI SubclassesOf $WMIServices not giving all the objects ?
by marto (Cardinal) on Jan 23, 2006 at 12:07 UTC
    Hi secret,

    Try:
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Win32::OLE qw (in); my $Computer="."; my $WMIServices = Win32::OLE->GetObject("winmgmts:\\\\" . $Computer . +"\\root\\cimv2"); my $WMIClasses = $WMIServices->SubclassesOf; foreach my $objItem (in $WMIClasses) { print Dumper($objItem); }

    Hope this helps.

    Martin

    Update: added formatting.
Re: WMI SubclassesOf $WMIServices not giving all the objects ?
by secret (Beadle) on Jan 23, 2006 at 13:08 UTC