|
Answer» I found a batch file that was supposed to keep any process open while the batch is running, but it doesn't work. No MATTER what I do, it always says that the process is not open.
Here is the batch (Credits to Foxhound)
Code: [Select]@echo off mode con cols=35 lines=10 title Keep a process open. set /p ppath=Enter the folder where the process is located in: cls set /p pname=Enter the exact name of the process you wish to keep open: cd %ppath% :LOOP cls tasklist | find "%pname%" >nul if %errorlevel%==1 ( color 0c echo Program not found. Starting %pname% start %pname% goto WAIT ) if %errorlevel%==0 ( color 0a echo Program found. Skipping start. goto wait ) :wait timeout /t 5 /NOBREAK >nul goto loop
Could someone PLEASE tell me how to fix it, or have any other batch files like this that work?
Thanks
I cleaned up your code and added a TRAP to to prevent a code malfunction that would send the batch file into a loop of opening endless cmd windows.
I suspect this file does not do what you think it does. When a process in no longer on the tasklist, it will start a new instance of the program, however the previous instance will be long terminated. It will not keep a process open, just create a new one.
If there are multiple copies of a process, how do you distinguish between them?
Code: [Select]@echo off
title Keep a process open. set /p ppath=Enter the folder where the process is located in:
set /p pname=Enter the exact name of the process you wish to keep open: if not exist %ppath%\%pname% ( echo %ppath%\%pname NOT found goto :eof ) cd %ppath%
:loop tasklist | find "%pname%" >nul if errorlevel 1 ( color 0c echo Program not found. Starting %pname% start %pname% goto wait ) if not errorlevel 1 ( color 0a echo Program found. Skipping start. goto wait ) :wait timeout 5 >nul goto loop
|