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

# ------ KONFIGURACJA SKRYPTU ------
$strProcess = 'calc.exe'; # nazwa obrazu monitorowanego procesu
$strComputer = '.';
# ------ KONIEC KONFIGURACJI ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colProcesses = $objWMI->ExecNotificationQuery('select * from __instanceDeletionevent ' . ' within 2 where TargetInstance isa \'Win32_Process\' ' . ' and TargetInstance.Name = \'' . $strProcess . '\'');
while (1) {
    $objProcess = $colProcesses->NextEvent;
    print 'Zakoczono proces ', $strProcess, ' (', $objProcess->TargetInstance->ProcessID, ') terminated', "\n";
    $intRC = $objWMI->Get('Win32_Process')->Create($strProcess,"", "", \$intProcessID);
    if ($intRC == 0) {
        print $strProcess, ' zosta uruchomiony.\n";
    }
    else {
        print $strProcess, ' nie zosta uruchomiony.  Kod bdu: ', $intRC, "\n";
    }
}
