in reply to How to kill a windows process by command name?

Thanks to everyone, I figured this out, here's the code:
use strict; use Win32::Process::Info; use Win32::Process; Win32::Process::Info->Set(variant=>'WMI'); my $pi = Win32::Process::Info->new(); for($pi->ListPids){ my ($info) = $pi->GetProcInfo($_); if($info->{CommandLine} eq 'perl foo.pl a'){ my $obj; my $pid = $info->{ProcessId}; Win32::Process::Open($obj,$pid,1); $obj->Kill(0); print "Killed $pid\n\n"; } }

Replies are listed 'Best First'.
Re^2: How to kill a windows process by command name?
by BrowserUk (Patriarch) on Nov 18, 2005 at 20:54 UTC

    You could replace the use of Win32::Process with a call to perl's built-in kill using a signal value of 2 (or 21 or -9 work, as do many others).

    use strict; use Win32::Process::Info; Win32::Process::Info->Set(variant=>'WMI'); my $pi = Win32::Process::Info->new(); for($pi->ListPids){ my ($info) = $pi->GetProcInfo($_); if($info->{CommandLine} eq 'perl foo.pl a'){ my $obj; my $pid = $info->{ProcessId}; kill 2, $pid; print "Killed $pid\n\n"; } }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.