Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Active Process

by AcidHawk (Vicar)
on Oct 01, 2003 at 03:44 UTC ( [id://295508]=note: print w/replies, xml ) Need Help??


in reply to Active Process

I am not sure I know exactally what you need but what follows is some code to list all the active processes and their pids. Inotepad is running it will kill it.. if several notepads are running they will ALL be killed.
#! /usr/bin/perl use strict; use warnings; use Win32::OLE qw( in ); use Win32::OLE::Variant; use Win32::Process; my $srv = "\\\\" . $ENV{'COMPUTERNAME'}; my $CLASS = "winmgmts:{impersonationLevel=impersonate}$srv\\Root\\cimv +2"; my $WMI = Win32::OLE->GetObject( $CLASS ) || die; foreach my $Proc ( in($WMI->InstancesOf( "Win32_Process" ) ) ) { if ($Proc->{Name} =~ /^notepad/i) { printf( "%d\t- %s ***KILLING***", $Proc->{ProcessID}, $Proc->{ +Name}); print "\n"; Win32::Process::KillProcess($Proc->{ProcessID}, 0); } else { printf( "%d\t- %s", $Proc->{ProcessID}, $Proc->{Name}); print "\n"; } }

-----
Of all the things I've lost in my life, its my mind I miss the most.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-19 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found