in reply to find out, if process with $PID exists (under Windows!)

Try something like

#!/usr/bin/perl use strict; use warnings; use Win32::OLE qw( in ); use Win32::OLE::Variant; use Win32::Process; my $CLASS = "winmgmts:{impersonationLevel=impersonate}\\\\$ENV{COMPUTE +RNAME}\\Root\\cimv2"; my $WMI = Win32::OLE->GetObject( $CLASS ) || die "Cannot Get list of P +IDS\n"; foreach my $Proc ( sort {lc $a->{Name} cmp lc $b->{Name}} in( $WMI->In +stancesOf( "Win32_Process" ) ) ) { if ($Proc->{Name} eq "Whatever you are looking for.exe") { print "$Proc->{ProcessID} is STILL RUNNING\n"; # We Dont Want to KILL the PID ---Win32::Process::KillProcess( +$Proc->{ProcessID}, 5); # Other Processing Here..;-) } }
If on the other hand you already know the PID you can simply run
use Win32::process; Win32::Process::KillProcess($PID,5);
Keep in mind though that $PID is a perlvar and if I ma correct returns the PID of perl.exe that is running your current script. Maybe you should change your var name..

Code Ripped from a working script I have running... This peice has not been tested on its own but should work..;-)

Update: Thanks to BrowserUk for reminding me what the question really was..!

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

Replies are listed 'Best First'.
Re: Re: find out, if process with $PID exists (under Windows!)
by BrowserUk (Patriarch) on Apr 09, 2003 at 14:36 UTC

    The OP didn't want to kill a specific process, only find out if it was still running.


    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.

      OOPS... I did read that, but got carried away with ripping a peice of code that I had previously put together that I forgot what the question was... :-(

      My First piece of code still works just don't do the kill peice...;)

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