# Name: _getProcessesWin32 # Desc: gets ids and names for currently running processes on Win32 platforms # In: None # Out: hash of process id, name pairs sub _getProcessesWin32 { my (%counter,%rCounter,%processList); Win32::PerfLib::GetCounterNames('',\%counter); %rCounter = reverse(%counter); # Get id for the process object and process counter my $processObj = $rCounter{'Process'}; my $processId = $rCounter{'ID Process'}; # create connection to local computer my $perfLib = new Win32::PerfLib(''); my $procRef = {}; # get the performance data for the process object $perfLib->GetObjectList($processObj, $procRef); $perfLib->Close(); # get current processes my $instanceRef = $procRef->{'Objects'}->{$processObj}->{'Instances'}; foreach my $instance (values %{$instanceRef}) { my $counterRef = $instance->{'Counters'}; foreach my $counter (values %{$counterRef}) { if($counter->{'CounterNameTitleIndex'} == $processId) { my $pid = $counter->{'Counter'}; $processList{$pid} = $instance->{'Name'}; } } } return %processList; }