Try something like
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE qw( in );
use Win32::OLE::Variant;
use Win32::Process;
my $CLASS = "winmgmts:{impersonationLevel=impersonate}\\\\$ENV{COMPUTE
+RNAME}\\Root\\cimv2";
my $WMI = Win32::OLE->GetObject( $CLASS ) || die "Cannot Get list of P
+IDS\n";
foreach my $Proc ( sort {lc $a->{Name} cmp lc $b->{Name}} in( $WMI->In
+stancesOf( "Win32_Process" ) ) )
{
if ($Proc->{Name} eq "Whatever you are looking for.exe")
{
print "$Proc->{ProcessID} is STILL RUNNING\n";
# We Dont Want to KILL the PID ---Win32::Process::KillProcess(
+$Proc->{ProcessID}, 5);
# Other Processing Here..;-)
}
}
If on the other hand you already know the PID you can simply run
use Win32::process;
Win32::Process::KillProcess($PID,5);
Keep in mind though that $PID is a perlvar and if I ma correct returns the PID of perl.exe that is running your current script. Maybe you should change your var name..
From the perlvar help - ($PID/$$) "The process number of the Perl running this script. You should consider this variable read-only, although it will be altered across fork() calls."
Code Ripped from a working script I have running... This peice has not been tested on its own but should work..;-)
Update: Thanks to BrowserUk for reminding me what the question really was..!
-----
Of all the things I've lost in my life, its my mind I miss the most.