natty_dread has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to kill mspaint.exe on my P.C. leveraging WMI. Everything in the code works below except the terminate command. Evolution of this script will be to terminate processes on remote pc's. I WANT TO USE WMI and not some flaky perl mod. Here's the code:
use strict; use Win32::OLE; my $refWMI = Win32::OLE->GetObject("winMgmts:"); ###### Get Processes mins. my $strQuery = "Select * FROM Win32_Process WHERE Name='mspaint.exe'"; my $colProcesses1 = $refWMI->ExecQuery ($strQuery); foreach my $refPS (in $colProcesses1) { print $refPS->{Name} . " is running \n"; sleep (5); $refPS->Terminate(); } undef $colProcesses1; undef $refWMI;

Replies are listed 'Best First'.
Re: killing processes w/WMI
by Anonymous Monk on Dec 03, 2004 at 13:36 UTC
    The terminate works on my machine (Xp Sp2 Perl 5.6.1)
      Works fine too, on my Win2k SP4, AS 5.6.1 ... after removing the line that says  mins.