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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|