csotzing has asked for the wisdom of the Perl Monks concerning the following question:

What I want to do is if $^O is Windows, find out if a certain process, that I know by name, is running. (I don't want my perl script to run when the other process is running.)

Does anyone know how to do this on Windows?

Replies are listed 'Best First'.
Re: Windows - Find Process by Name
by strat (Canon) on Apr 19, 2002 at 13:40 UTC
    or: 151368: Process mgmt on WinNT

    Best regards,
    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Re: Windows - Find Process by Name
by talexb (Chancellor) on Apr 19, 2002 at 13:30 UTC
    Try 24585 and 21069. I got that and many more just by searching on "Win32 list".

    Search is your friend. :)

    --t. alex

    "Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

Re: Windows - Find Process by Name
by Dog and Pony (Priest) on Apr 19, 2002 at 13:15 UTC
    Use Win32::PerfLib, that should be included in for instance ActiveState perl. :)
    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
      It's not clear from the Win32::PerfLib docs, but if you execute the sample snippet,
      use Win32::PerfLib; my $server = ""; Win32::PerfLib::GetCounterNames($server, \%counter); %r_counter = map { $counter{$_} => $_ } keys %counter; # retrieve the id for process object $process_obj = $r_counter{Process}; # retrieve the id for the process ID counter $process_id = $r_counter{'ID Process'}; # create connection to $server $perflib = new Win32::PerfLib($server); $proc_ref = {}; # get the performance data for the process object $perflib->GetObjectList($process_obj, $proc_ref); $perflib->Close(); $instance_ref = $proc_ref->{Objects}->{$process_obj}->{Instances +}; foreach $p (sort keys %{$instance_ref}) { $counter_ref = $instance_ref->{$p}->{Counters}; foreach $i (keys %{$counter_ref}) { if($counter_ref->{$i}->{CounterNameTitleIndex} == $proce +ss_id) { printf( "% 6d %s\n", $counter_ref->{$i}->{Counter}, $instance_ref->{$p}->{Name} ); } } }
      it gives you a process list.
      --
      Mike
Re: Windows - Find Process by Name
by demerphq (Chancellor) on Apr 19, 2002 at 14:09 UTC
    Have a look at Win32 Process Info that I just posted. Hopefully it will do the trick.

    :-)

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

Re: Windows - Find Process by Name
by Rex(Wrecks) (Curate) on Apr 19, 2002 at 16:38 UTC
    Also look at my reply here. This little piece of code will print out an enumerated proccess list in Windows. Just pull out the pieces you don't need.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: Windows - Find Process by Name
by csotzing (Sexton) on Apr 19, 2002 at 13:57 UTC
    Thanks to all for the info!

    -CS