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

I need to locate a PID of a specific process and kill it. Here's the catch. The process is on a remote computer, and multiple instances of the process are running. The only way to distinguish them in NT task manager is by the user name. For example, process.exe is being run by 'John' and process.exe is being run by 'Frank' How do I kill the process being run by 'John'?
  • Comment on Getting process ID to kill a process....

Replies are listed 'Best First'.
Re: Getting process ID to kill a process....
by $code or die (Deacon) on Sep 13, 2001 at 10:01 UTC
    The following node explains how to get a list of processes and IDs: Getting a Local/Remote Win32 Task List.

    Another option is using WMI (Win32_Process class). I don't have any code for this. But if you do a Super Search for WMI or "Win32 process" you will probably get some more useful information. Also see MSDN for WMI specifics.

    Good Luck.

    $,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
    =~y'_"' ';eval"die";print $_,lc substr$@,0,3;
Re: Getting process ID to kill a process....
by rrwo (Friar) on Sep 13, 2001 at 12:31 UTC

    Here's some code I have sitting around, though it now seems broken since I've upgraded to Perl 5.6.1 (along with many other Win32 modules in ActiveState).

    See the book Win32 Perl Scripting: The Administrator's Handbook by Dave Roth.

    use Win32::IProcess 1.4, qw( PROCESS_ALL_ACCESS PROCESS_QUERY_INFORMATION PROCESS_TERMINATE NONINHERITED ); my $pobj = new Win32::IProcess; getPids(); sub getPids { my ( @proc_list, @result ); $pobj->EnumProcesses( \@proc_list ) or die "Unable to enumerate processes: $!"; foreach my $process ( @proc_list ) { my $pid = $process->{ProcessId}; my $name = lc($process->{ProcessName}); print STDERR $pid, "\t", $name, "\n"; } return @result; }