I want to check using a bat file if a Java program is already running. If its not running then start it using start javaw
.
I have tried WMIC
and I am only successful so far to get the PID.
WMIC process where "CommandLine like '%MyServer.jar%' and Name like '%javaw%'" get ProcessId
But how to write an if else condition in the bat file to start?
I tried using tasklist and find
tasklist /FI "IMAGENAME eq myapp.exe" 2>NUL | find /I /N "myapp.exe">NUL
if "%ERRORLEVEL%"=="0" echo Programm is running
But for all the java applications myapp.exe
will be java.exe
.
Please help...
P.S: There are options for this to be done via the Java program itself, but my specific situation asks for a bat file solution.