Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. SETLOCAL EnableExtensions
  2.  
  3. REM Enter the application information.
  4. SET AppName=Application Name
  5. SET ExeFile=FileToLaunch.exe
  6. SET ExePath=C:PathToApplication
  7.  
  8. REM Select the conditions to kill the application.
  9. REM A value of 1 = Yes, 0 = No
  10. SET KillIfRunning=1
  11. SET KillIfNotResponding=1
  12. SET KillIfUnknownStatus=1
  13.  
  14. REM Specify when to start the application:
  15. REM 1 = Start only if the process was previous killed.
  16. REM 0 = Start the application regardless.
  17. SET StartOnlyIfKilled=1
  18.  
  19. SET KillStatus="%TEMP%KillStatus.tmp.txt"
  20. SET Success=0
  21.  
  22. ECHO Killing existing %AppName% instance...
  23. IF {%KillIfRunning%}=={1} CALL :CheckKillStatus "%ExeFile%" "RUNNING"
  24. IF {%KillIfNotResponding%}=={1} CALL :CheckKillStatus "%ExeFile%" "NOT RESPONDING"
  25. IF {%KillIfUnknownStatus%}=={1} CALL :CheckKillStatus "%ExeFile%" "UNKNOWN"
  26. ECHO.
  27.  
  28. IF {%StartOnlyIfKilled%}=={1} (
  29. IF {%Success%}=={0} GOTO End
  30. )
  31. ECHO Restarting %AppName%...
  32. START "%ExeFile%" "%ExePath%%ExeFile%"
  33. ECHO.
  34.  
  35. IF EXIST %KillStatus% DEL /F /Q %KillStatus%
  36.  
  37. ENDLOCAL
  38.  
  39.  
  40. :CheckKillStatus
  41. ECHO Killing with status: %~2
  42. TASKKILL /FI "STATUS eq %~2" /IM "%~1" /F > %KillStatus%
  43. SET /P KillResult= < %KillStatus%
  44. FOR /F "tokens=1,* delims=:" %%A IN ("%KillResult%") DO (
  45. ECHO %%A:%%B
  46. IF /I {%%A}=={SUCCESS} SET /A Success=%Success%+1
  47. )
  48.  
  49.  
  50. :End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement