Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Kill process program??

by AcidHawk (Vicar)
on Apr 29, 2004 at 07:00 UTC ( #349033=note: print w/ replies, xml ) Need Help??


in reply to Kill process program??

Check out Win32 Perl Scripting: The Administrator's Handbook by Roth. There are loads of Admin script in there.

Also check his script repository for more admin scripts.

Update: I include a simple script that takes a command line parameter and searches for that in the process list and kills all instances found.. to test simply launch many notepad.exe processes.. then run the following script I.e. pkill.pl notepad

#! /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 <app name>\n"; print "<app name> = name and extension or (part therof I.e. note f +or notepad) of process to kill\n"; }
-----
Of all the things I've lost in my life, its my mind I miss the most.


Comment on Re: Kill process program??
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://349033]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-08-01 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (51 votes), past polls