#!/usr/local/bin/perl use strict; use warnings; use Win32::Process; use Win32::Process::Info; my $Process_Obj = Win32::Process::Info->new (undef , "NT"); my @info = $Process_Obj->GetProcInfo (); my $Pid; my $Name; my %Process; for my $i ( 0 .. $#info ){ $Pid = $info[$i]{"ProcessId"}; $Name = $info[$i]{"Name"}; print "$Pid \t $Name \n"; $Process{$Pid} = $Name; } print "What program do you want to kill?\n"; my $exit_code = 1; my $kill = <STDIN>; chomp $kill; Win32::Process::KillProcess($kill, $exit_code)
Update: Simplified for loop to only focus on name and Pids
This works for me. Now I broke down the data structure to show the important bits of Win32::Process::Info . And I am getting my PID from STDIN but you can use the Name and Process ID keys from the Win32::Process::Info to identify the process you want to kill and then call Win32::Process::KillProcess to end it. But you need to make sure in that case that the PID is a running process. I don't know how you are determining the PID programatically on how this will work.

If you give more specifics I can show more specific examples this is done in a way to show where the PID can come from.

Update: I am trying to simplify the id, in your intial post you did not show where your PID was coming from. For this to work we need to know how you are determining the pid to kill. In this example I am printing a list and having the user choose but the same information can be used programatically to kill processes. I tend to search for a name and kill all instances of that name. But again this is just an example. If you need any more info just describe what you are doing with a bit more detail and I will try to help.

"No matter where you go, there you are." BB

In reply to Re: Re: Re: Win32::Process::KillProcess by Ninthwave
in thread Win32::Process::KillProcess by jimbobfurley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.