Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Answer: How do i kill a process on a remote win32 machine

by Util (Priest)
on Apr 03, 2002 at 02:08 UTC ( #156206=categorized answer: print w/replies, xml ) Need Help??

Q&A > programs and processes > How do i kill a process on a remote win32 machine - Answer contributed by Util

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 # 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: COSMOS 952
produced this output:
Killing:    952 winbff32.exe

Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-05-27 00:30 GMT
Find Nodes?
    Voting Booth?