如何使.bat文件检查程序并在未打开的情况下重新启动,以及在已运行x倍的时间内重新启动该程序?

时间:2018-08-28 17:43:31

标签: batch-file

如果需要的话,这可以是两个单独的.bat文件,但是如果可以的话,我希望这样做。

我需要运行某个程序,但有时会崩溃。

到目前为止,我已经将其用于.bat。

它可以每小时重置一次程序,但是有时会在两次重启之间崩溃。

我只想检查一下,所以如果找不到该程序,它将启动。

有可能吗?

@echo off
:loop
start "xx" "xxpath"
timeout /t 3600 >null
taskkill /f /im "xx" >null
timeout /t 4 >null
goto loop

1 个答案:

答案 0 :(得分:0)

这是一个示例批处理,可以检查chrome.exe的任何实例是否正在运行

如果没有,我们就开始吧!

@echo off
Color 0A
Set WaitTimeSeconds=20
Set App_Path=C:\Program Files\Google\Chrome\Application\chrome.exe
for %%i in (%App_Path%) do set App_Name=%%~nxi
Title Checking if any "%App_Name%" instance is running ... 
:Loop
Rem Clear the screen
cls 
Rem Kill any application that have a status equal to not responding !
Taskkill /f /fi "status eq not responding">nul 2>&1
Rem Check if any application instance is running ; if not we start it !
TASKLIST | FINDSTR %App_Name% || START "" "%App_Path%"
Timeout /t %WaitTimeSeconds% /nobreak>nul
Goto Loop