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

Fellow Monks,

I tried supe search, but maybe I just put in the wrong queries, its a newbie question here, the title says it all. Is perl capable of stopping processes on a windows machine? (actually its a remote machine with shared drives, if that makes a difference) For example, if an exe is running, can perl tell the os to make it stop? I'm very new to perl, so any pointers would be highly appreciated. If anybody has some sample code that does something similar that would be great, as I am keen to learn from example.

Jonathan

  • Comment on using perl to stop processes on windows

Replies are listed 'Best First'.
Re: using perl to stop processes on windows
by esskar (Deacon) on Mar 03, 2004 at 19:41 UTC
    use strict; use Win32; use Win32::Process; use Win32::Process::Info; my $exe = "yourexe.exe"; my $pi = Win32::Process::Info->new("\\\\someserver.domain.de"); foreach my $hashref ($pi->GetProcInfo()) { my $exitcode = undef; print "Process: $hashref->{Name}\n"; if(lc($hashref->{Name}) eq $exe) { Win32::Process::KillProcess($hashref->{ProcessId}, $exitcode); } }
Re: using perl to stop processes on windows
by the_0ne (Pilgrim) on Mar 03, 2004 at 16:39 UTC
Re: using perl to stop processes on windows
by inman (Curate) on Mar 03, 2004 at 16:38 UTC
    Lookup the pskill utility available on the sysinternals site. This should do what you want. You can use Perl to drive this tool.
Re: using perl to stop processes on windows
by maa (Pilgrim) on Mar 03, 2004 at 19:40 UTC

    Hi,

    pskill & psexec are fine utilities indeed, but to answer your question, "Yes, Perl can kill processes on a remote Win32 workstation."

    Perl will need the help of WMI, though! This should be installed by default on W98 - XP machines.

    If you have the NTReskit, check out the kill.vbs script which does exactly this. If you want to convert that to Perl using Win32::OLE then why not post the results here afterwards :-)

    You should also check out Dave Roth's site and nodes like How to Start a Process in a Remote Win32 Machine using Perl and WMI for other examples of getting process listings under Win32.

    HTH - Mark