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

Hi all-
I have a script that gets the process name of currently running Win32 processes... BUT I can't figure out how to get the command-line arguments for that process (so that it will resemble the name in a ps command on Unix)
For example, if I have "perl temp.pl" running on Win32, I can get the process's name as "perl", but I can't figure out how to get the process's name as "perl temp.pl". I'm using Win32::PerfLib to get the process ids and names:
# Name: _getProcessesWin32 # Desc: gets ids and names for currently running processes on Win32 pl +atforms # 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; }
I need the full name, so that I can distinguish between different perl and/or java processes that are running--so I know what to kill and what to leave alone. Any help is appreciated!
-C
print(map(lc(chr),split(6,qw/99672682673683684689632658645641610607/)));

Replies are listed 'Best First'.
Re: Win32 Process name with arguments
by traveler (Parson) on Sep 06, 2002 at 18:55 UTC
    This is a very interesting question! It seems that MKS and Cygwin ps tools don't show the command line. A lot of searching on MSDN returned only results showing how a process can get its own args. So, the question is, can it be done at all? Have you (or any other monks) seen a program that lists commant arguments for all commands on the system? If so, the source for that program may point the way.

    BTW, I also checked the sources section for sysinternals to no avail.

    --traveler

Re: Win32 Process name with arguments
by Marza (Vicar) on Sep 06, 2002 at 20:09 UTC

    There was a mod that might have done what you needed. It was called Win32::IProcess. However, I don't think it is maintained anymore.

    You have an example of its use on this site: Bug fixes for all your issues

    I found a copy of it on this site as well: idnopheq list

      traveler, there should be some way of doing this. I can see the command line parameters with the MKS ps. Hopefully I can figure out how...

      Marza, Thank you for the suggestion of Win32::IProcess. It looks like this could possibly be a solution, though I'm very hesitant about using a module which isn't supported... even the website listed with the module isn't valid anymore. (I probably wouldn't be so hesitant if it were just for my own personal use)

      I might look at IProcess some more, but I'll probably keep searching around to see if there are any other ways I can get process arguments. Thanks for the suggestions!

      -C
      print(map(lc(chr),split(6,qw/99672682673683684689632658645641610607/)));