All,

 

I've been working on a script to grab the owner of processes on my
systems and it works great if I limit it to one machine at a time.  If
try to pass it multiple hostnames in a loop, it bombs out after the
first host is completed.  I've Googled, checked the docs for the module,
and checked ActiveState's lists but can't seem to find a way around
this.  See code below...

 

--begin code--

 

use warnings;

use strict;

 

use Win32::Process::Info;

 

my @servers = (

  'this',

  'that',

  'theother',

);

 

@servers = sort @servers;

 

#my $server = 'this';

 

sub getProcInfo {

            my ( $server ) = @_;

            print "\n-- $server --\n";

            my $processObj = Win32::Process::Info->new( $server, 'WMI'
);

            my @procInfo = $processObj->GetProcInfo();

 

            # this should give us a list of anonymous hashes...

            foreach my $info ( @procInfo ) {

                        if ( ref $info ) {

                                    my $procName;

                                    my $procOwner;

                                    foreach my $key ( keys %{ $info } )
{

                                                # grab the keys first...

                                                #print "$key\n";

                                                #print $key . " = " . ${
$info }{ $key } . "\n" if ( $key eq 'Name' );

                                                #print $key . " = " . ${
$info }{ $key } . "\n" if ( $key eq 'Owner' );

                                                $procName = ${ $info }{
$key } if ( $key eq 'Name' );

                                                $procOwner = ${ $info }{
$key }   if ( $key eq 'Owner' );

                                    }

 

                                    if ( $procName and $procOwner ) {

                                                            #print "\n";

                                                            print
$procName . ": " . $procOwner . "\n";

                                    }

 

                        } else {

                                    print "Info: $info\n";

                        }

            }

}

 

foreach my $server ( @servers ) {

            getProcInfo( $server );

}

 

--end code-

 

Any help is appreciated.

 

ry

Reply via email to