Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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
VinsWorldcom takes a cookie from the platter on the sideboard.
Discipulus take his wine and hope the coockie is a 'tozzetto alle mandorle'

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-04-26 20:31 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (488 votes). Check out past polls.