Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How do i kill a process on a remote win32 machine

by cab (Beadle)
on Apr 02, 2002 at 08:55 UTC ( #155959=perlquestion: print w/replies, xml ) Need Help??

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

  • Comment on How do i kill a process on a remote win32 machine

Replies are listed 'Best First'.
Re: How do i kill a process on a remote win32 machine
by Util (Priest) on Apr 03, 2002 at 02:08 UTC

    Use WMI (Windows Management Instrumentation).

    This book has 2 pages on WMI details, and 4 sample programs:
    Win32 Perl Scripting: The Administrator's Handbook

    This book has 7 pages on WMI details, and 4 code snippets:
    Perl for System Administration: Managing multi-platform environments with Perl

    A WMI tutorial, SDK, and documentation are available for download from Microsoft.

    Working skeleton code, derived (and bug-fixed) from both books:

    #!/usr/bin/perl -W # WMI_for_monks.pl use warnings 'all'; use strict; use Win32::OLE('in'); my ($Machine, $pid_to_kill) = @ARGV; $Machine =~ s{^[\\/]{2,}}{}; my $CLASS = 'WinMgmts:{impersonationLevel=impersonate}!//' . $Machine; my $WMI = Win32::OLE->GetObject( $CLASS ) or die Win32::OLE->LastError(); foreach my $proc (in $WMI->InstancesOf('Win32_Process')){ next unless $proc->{ProcessId} == $pid_to_kill; printf "Killing:%7d\t%s\n", $proc->{ProcessId}, $proc->{Name}; $proc->Terminate(0); }

    This command:
    WMI_for_monks.pl COSMOS 952
    produced this output:
    Killing:    952 winbff32.exe

Re: How do i kill a process on a remote win32 machine
by Marza (Vicar) on Apr 02, 2002 at 20:06 UTC

    Use the Win32::Service

    You have a function

    StopService(hostName, serviceName) http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/site/lib/Win32/Service.html
Re: How do i kill a process on a remote win32 machine
by Marza (Vicar) on Apr 03, 2002 at 01:30 UTC

    Strange by my reply disappeared.

    Here it is again...

    Sorry, usually when I get a process question, they mean service....

    Take a look at Win32::Process

    You will have a function

    Win32::Process::KillProcess($pid, $exitcode)

    Terminates any process identified by $pid. $exitcode will be set to the exit code of the process.

    http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/site/lib/Win32/Process.html

      Ignore this! A case of posting without a license!

      This is only works locally!

      Thanks to Util for catching this!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://155959]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-04-18 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?