Batch file for "if" exe "is not running (task manager) then do this task"?
I don't know anything about batch files and I am doing something for something. I want to write a batch file that will run in the background that will deal with it itself to make sure "java.exe" is running, and if not, it will initiate another batch file ( say 'abc.bat' )
This 'abc.batch' sets some parameters and runs java.exe which executes those parameters. I want this "java.exe" to keep running and if anyone closes it, it should restart right away by executing "abc.bat". Moreover, I don't want to make changes to 'abc.bat'.
If this is confusing, I would like to apologize for my writing skills and I would like you to ask for clarification.
+3
source to share
1 answer
@if (@X)==(@Y) @end /* JSCRIPT COMMENT **
@echo off
set process_to_check=java.exe
:repeat
cscript //E:JScript //nologo "%~f0" | find /i "%process_to_check%" >nul 2>&1 && (
echo process %process_to_check% is running
) || (
echo process %process_to_check% is not running
call abc.bat
)
rem wait 5 minutes
ping localhost -n 1 -w 300000 >nul
exit /b
************** end of JSCRIPT COMMENT **/
var winmgmts = GetObject("winmgmts:\\\\.\\root\\cimv2");
var colProcess = winmgmts.ExecQuery("Select * from Win32_Process");
var processes = new Enumerator(colProcess);
for (;!processes.atEnd();processes.moveNext()) {
var process=processes.item();
WScript.Echo( process.processID + " " + process.Name );
}
+2
source to share