Reputation: 58
For definitely not malicious reasons, I need to have a batch file always open. I have some base code:
:b
echo off
tasklist /fi "imagename eq cmd.exe" |find ":" > nul
if errorlevel 1 taskkill /f /im "game.bat"&start game.bat
goto b
And it works fine if want notepad.exe or blah.txt and etc. Except for batch files, as the program itself is a batch file, the system sees cmd.exe is already open.
Upvotes: 1
Views: 459
Reputation: 7921
Give your batch file a Title
by adding the following command to game.bat
:
title %~nx0
Check if game.bat
is running by using tasklist
with /v
option:
:b
@echo off
tasklist /v | find "game.bat" > nul
rem errorlevel 1 means game.bat is not running, so start it
if errorlevel 1 start game.bat
rem timeout to avoid excessive processor load
timeout 60
goto b
Upvotes: 3