#! /usr/bin/perl use strict; use warnings; use Win32; use Win32::API; use Win32::Process; use Win32::OLE qw( in ); #Identify the Process that have been left to kill use Win32::OLE::Variant; #Identify the Process that have been left to kill my $app = $ARGV[0]; if ($app) { my $rc = 1; my $srv = "\\\\" . $ENV{'COMPUTERNAME'}; my $CLASS = "winmgmts:{impersonationLevel=impersonate}$srv\\Root\\cimv2"; my $WMI = Win32::OLE->GetObject( $CLASS ) || die; foreach my $Proc ( sort {lc $a->{Name} cmp lc $b->{Name}} in( $WMI->InstancesOf( "Win32_Process" ) ) ) { my $regex1 = "($app)"; if ($Proc->{Name} =~ /$regex1/i) { print "INFORMATION - About to kill $Proc->{ProcessID} for $app\n"; unless (Win32::Process::KillProcess($Proc->{ProcessID}, 0)) { print "Could not kill $Proc->{ProcessID} for $app\n"; } } } } else { print "$0 \n"; print " = name and extension or (part therof I.e. note for notepad) of process to kill\n"; }