If the process has an identifiable name, then you could look up the process id from the name using Win32::PerfLib.
This is a simple "process list" script that may or may not help. The api is somewhat confusing at first due to the sparse documentation for the module and the complexity of the underlying api.
#! perl -w use strict; use Win32::PerfLib; my (%counters, %r_counters); Win32::PerfLib::GetCounterNames('', \%counters); # Build a reverse lookup table. Names are clearer than numbers. @r_counters{values %counters} = (keys %counters); # retrieve the id for process object my $processObj_id = $r_counters{Process}; # retrieve the id for the process ID counter my $processCounter_id = $r_counters{'ID Process'}; my %processes; # create connection to $server my $perflib = new Win32::PerfLib(''); # get the performance data for the process object $perflib->GetObjectList($processObj_id, \%processes); $perflib->Close(); my $pInstances = $processes{Objects}{$processObj_id}{Instances}; foreach my $p (keys %{$pInstances}) { my $pICounters = $pInstances->{$p}{Counters}; foreach my $i (keys %{$pICounters}) { if($pICounters->{$i}{CounterNameTitleIndex} == $processCounter +_id) { printf( "% 6d %s\n", $pICounters->{$i}{Counter}, $pInstances->{$p}{Name} ); } } }
Once you have the proc_id you could use Win32::Process::KillProcess($pid, $exitcode) Though whether this is any better (or even any different) to using Perl's built in kill I'm not sure.
Alternatively, if you can modify the script that you want to kill, you could have it create and periodically check the state of a named Win32::Event. The all your kill script needs to do is open that named event$event = Win32::Event->open($name), and then set it $event->set. Then next time the condemned script checks the state of the Event $event->wait([$timeout]), it can commit hari-kari by whatever method you select.
Of course this is analogous to the Perl signaling mechanism. I have wondered why AS never implemented signals this way under the covers, but there is probably a good reason.
Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.
In reply to Re: Shutting down a windows perl script?
by BrowserUk
in thread Shutting down a windows perl script?
by buzzthebuzzsaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |