Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

killing windows process 1

Status
Not open for further replies.

ranadhir

Programmer
Nov 4, 2003
54
IN
Is there a way to get the handle of a windows process by name(e.g. IEXPLORE.exe) ,and kill it from a perl script.
We execute a windows application from a perl script.If the execution time of the application exceeds a particular interval,we need to forcefully kill it.
 
Windows has always been weak in this area, but they introduced a new program called taskkill in Windows XP. You could execute it with a system call from a perl script.

c:\>taskkill /? # get all the details on usage

Or I would recommend using a third party command line app.

This freeware app looks very good:

I have also used pslist to get the name of a process and pskill to terminate. It works good as well.

 
Or use Win32::process::Info

Code:
my $pi = new Win32::Process::Info;

my @info = $pi->GetProcInfo;

foreach (@info) {
   # close all programs named aim.exe
   if ($_->{Name} eq 'aim.exe') {
      my $i = kill (1, $_->{ProcessId}) or die "Can't kill: $!";
      print "$i processes killed\n";
   }
}
 
in conjuction with raklet's taskkill approach, you can also use tasklist to get a list of processes and their pid's.

Having said that Kirsle's approach is much cleaner ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top