• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2786
  • Last Modified:

kill process by name with Perl in win32


I want to kill a process given its name "notepad.exe",
I know that there is a function called kill to do this,
but its argument is processID rather than the process name.

I know Perl can get the PID if it spawns notepad.exe, but the notepad process exists before the perl script is called.

The module below seems to work for cygwin perl,
    http://search.cpan.org/~durist/Proc-ProcessTable-0.39/
but not ActiveState (cygwin is great but it doesn’t play well with clients when the Perl folder is on a network share)

Is there a killall equivalent for Perl that would work on win32?
0
Marketing_Insists
Asked:
Marketing_Insists
  • 2
1 Solution
 
turn123Commented:
Not very elegant but it worked for me when I had a similer problem.

use Win32::GuiTest qw(FindWindowLike SetForegroundWindow GetWindowText SendKeys);
use Win32::GUI;
my @windows = FindWindowLike(0, "Notepad");

for (@windows) {
      SetForegroundWindow($_);
      print GetWindowText($_);
      SendKeys("%{F4}");
};

You can find the modules via PPM if you don't have them installed already.

Go the the command line:
ppm -> "search GUI" -> choose the correct package and remember the number -> "install number" (number being the number your remembering).
0
 
Marketing_InsistsAuthor Commented:
LOL I was jsut playing with GuiTest to automate some un-scriptable gui app.  I didn't think of using it to kill stuff.

BTW the GuiTest version available on CPAN comes with a recorder that gives good hints on control functions.
0
 
turn123Commented:
Marketing_Insists,

Cool I'm glad to hear that they got it useable.  I tried it quite a while back and found that it was faster just to code it myself :-).

Turn123
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now