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;