use Win32::OLE;
$Win32::OLE::Warn = 3;

# ------ KONFIGURACJA SKRYPTU ------
$strProcess = 'calc.exe';
$strComputer = '.';
# ------ KONIEC KONFIGURACJI ---------

$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colProcesses = $objWMI->ExecNotificationQuery('select * from __instanceCreationEvent ' . ' within 1 where TargetInstance isa \'Win32_Process\' ' . ' and TargetInstance.Name = \'' . $strProcess . '\'');
while (1) {
    $objProcess = $colProcesses->NextEvent;
    print 'Koczenie procesu ' . $strProcess . ' (' . $objProcess->TargetInstance->ProcessID . ')', "\n";
    $objProcess->TargetInstance->Terminate();
}
