title: detect crashed application with .bat
body: <p>Hi guys is it possible to detect application crash with .bat code then restart that with .bat.
  pleas give me a method.
  i write a code to start and restart application but i don't know how to detect crashed application.
  thank you</p>
  
  <pre><code>@echo off 
  cls
  echo Protecting NpAPIserver from crashes...
  title NpAPIServer Watchdog
  
  tasklist /FI "aplication.exe" | find /i "aplication.exe" 
  for /f "tokens=2" %%x in ('tasklist ^| findstr aplication.exe') do set PIDTOKILL=%%x
  IF ERRORLEVEL 2 GOTO KILLPROGRAM
  IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM
  
  :KILLPROGRAM
  taskkill /F /PID %PIDTOKILL%
  goto LAUNCHPROGRAM
  
  :LAUNCHPROGRAM
  cd "c:\np"
  start aplication.exe
  goto WAITLUNCH
  
  :WAITLUNCH
  timeout /T 300
  for /f "tokens=2" %%x in ('tasklist ^| findstr aplication.exe') do set PIDTOKILL=%%x
  taskkill /F /PID %PIDTOKILL%
  goto LAUNCHPROGRAM
  </code></pre>