Uses pslist from the open source pstools suite from http://www.sysinternals.com to produce a hash containing current process data.

Takes a set of key,value pairs. Currently accepts 'process' and 'machine' keys. Will extend with additional pslist options at a later date. NOTE, leading \\ on machine name is optional, and process name should not have an extension.

There probably is a better way to do this, but this tool works on local and remote machines and its really easy to use...

;-)

Or maybe that isnt the best excuse?

use strict; use warnings; use constant Process_EXE => 'pslist.exe'; sub process_hash { my %params=@_; my $find_process=quotemeta($params{process}||""); my $machine =($params{machine}||""); $machine="\\\\".$machine if $machine && $machine!~/^\\\\/; open my $process,"pslist.exe $machine |" or die " Cant open pstool +s!"; my %processes; my @field_names=("Name","Pid","Pri","Thd","Hnd","Mem","User Time", +"Kernel Time","Elapsed Time"); while (<$process>) { chomp; my @process_data=split/\s+/; next unless @process_data==9; if ($process_data[1]=~/pid/i) { next } else { my %process; @process{@field_names}=@process_data; $processes{$process_data[0]}=\%process; return \%process if $process_data[0]=~/^$find_process$/i; } } return $find_process ? undef : \%processes; } use Data::Dumper; # All processes on local machine print Dumper(process_hash()); # Process info about explorer print Dumper(process_hash(process=>'explorer')); # Process list from a remote machine print Dumper(process_hash(machine=>'brahma'));

In reply to Win32 Process Info by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.