in reply to Get PID of an excel.exe opened by perl

The following shows how to find the PID's of running Excel instances.
use strict; use warnings; use Win32::Process::Info; use Data::Dumper; my $pi = Win32::Process::Info->new(); for ( $pi->ListPids ) { my ($info) = $pi->GetProcInfo ($_); print "Excel instance at PID $_.\n" if $info->{Name} =~ /excel\.ex +e/i; }
Sadly, I'm not sure how to find out, which file is opened by a specific instance. That is a bit more difficult, because each instance can open multiple files.

Update:
A possible way might be to
  1. Enumerate the windows in the system
  2. Find out which PID belongs to that window
  3. If the window belongs to one of your Excel instances, find out the windows' caption
  4. The part after the first dash of the caption (" - ") must be the filename (because Excels' windows normally have captions like "Microsoft Excel - File.xls")


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Get PID of an excel.exe opened by perl
by Nalina (Monk) on Jun 07, 2005 at 06:01 UTC
    Thanks for the reply. Please give me the url (or repository) to install Proc::ProcessTable using ppm on windows.
      Your new node here and your statement you want to kill a process on windows makes me wonder if you ever read the docs. To kill a process:
      Win32::Process::KillProcess($pid, $exitcode);


      holli, /regexed monk/