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
# 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
| 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)
http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/site/lib/Win32/Service.html | 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.
http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/site/lib/Win32/Process.html
|
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!
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
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|