Kill a process launched from a powershell script if it doesn't complete


hello,

i have powershell script launches external .exe like so:

  & c:\path executable\program.exe | out-null  

usually that's sufficient needs, program.exe errors , pops error message requires user click ok before script continues.  in order around issue, have following logic:

  start-sleep -s 60    if (get-process program -ea silentlycontinue)      {         stop-process -processname program         perform error handling steps      }  
question is, there way determine within powershell when exception occurs within in external executable?  i'd prefer able terminate process , continue script @ point, rather waiting 60 seconds make sure i've given executable enough time complete.

 

 

$proc = start-process "c:\path executable\program.exe" -passthru 
if (!$proc.waitforexit(60000)) {$proc.kill()} 




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...