kill process by name with Perl in win32

Posted on 2005-04-22
Last Modified: 2010-05-18

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,
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?
Question by:Marketing_Insists
    LVL 11

    Accepted Solution

    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) {
          print GetWindowText($_);

    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).

    Author Comment

    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.
    LVL 11

    Expert Comment


    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 :-).


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now