Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

How do i kill a process on a remote win32 machine

by cab (Beadle)
on Apr 02, 2002 at 08:55 UTC ( #155959=categorized question: print w/replies, xml ) Need Help??
Contributed by cab on Apr 02, 2002 at 08:55 UTC
Q&A  > programs and processes

Answer: 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 # 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

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

Use the Win32::Service

You have a function

StopService(hostName, serviceName)
Answer: How do i kill a process on a remote win32 machine
contributed by Marza

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.

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (2)
    As of 2020-10-25 22:28 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (249 votes). Check out past polls.