I am now using the code below to print a list of processes on the computer. It works. However, I would like to be able to tell which user is running each process. I need to be able to find a process with a certain name, running under a certain user account. How can I do this?

Thanks,
Lyle Kopnicky

##################

use Win32::PerfLib;

%proc_list = get_remote_process_list('');
foreach $i (keys %proc_list) {
   print "$i: $proc_list{$i}\n";
}

sub get_remote_process_list {

my $server = $_[0];

my %rtasks;
my %counter;

Win32::PerfLib::GetCounterNames($server, \%counter);
my %r_counter = map { $counter{$_} => $_ } keys %counter;
# retrieve the id for process object
my $process_obj = $r_counter{Process};
# retrieve the id for the process ID counter
my $process_id = $r_counter{'ID Process'};

# create connection to $server
my $perflib = new Win32::PerfLib($server);
my $proc_ref = {};
# get the performance data for the process object
$perflib->GetObjectList($process_obj, $proc_ref);
$perflib->Close();
my $instance_ref = $proc_ref->{Objects}->{$process_obj}->{Instances};
foreach my $p (sort keys %{$instance_ref})
{
   my $counter_ref = $instance_ref->{$p}->{Counters};
   foreach my $i (keys %{$counter_ref})
   {
       if($counter_ref->{$i}->{CounterNameTitleIndex} == $process_id)
       {
           $rtasks{$counter_ref->{$i}->{Counter}} =
               $instance_ref->{$p}->{Name};
       }
   }
}
 return %rtasks;
}

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to