Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

( #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 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 # 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

Comment on Answer: How do i kill a process on a remote win32 machine
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-10-23 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls