ShadowThief wrote:It won't work if you're checking to see if the verification script is running, but if you're checking to see if a second script is running (which is how I interpreted your question), then it absolutely will work.
OK
If OP want to do the check within a batch file, at least I understood it so, not from console, as you have shown it, then this might help
Code: Select all
:checkForBatchIsRunning
IF "%~1?" EQU "?" GOTO :EOF
SET "_window_title=%~1"
TASKLIST /FI "Status eq Running" /FI "Windowtitle eq %_window_title%" /FO "TABLE" | FINDSTR /c:"PID" > NUL && ( SET "is_running=1" ) || ( SET "is_running=0" )
SET "_window_title="
GOTO :EOF
Of course, the batch file OP is testing on, must have a window title set with TITLE command, which must be passed to the sub
Code: Select all
CALL :checkForBatchIsRunning "%known_window_title%"
The complete code that OP wanted to get then would be
Code: Select all
@ECHO OFF
SET known_window_title=blahblah
rem [magic check if the process is running]
CALL :checkForBatchIsRunning "%known_window_title%"
CLS
IF "%is_running%" EQU "0" (
ECHO The process %known_window_title% is not running.
) ELSE (
ECHO The process %known_window_title% is already running.
)
PAUSE
EXIT /b
:checkForBatchIsRunning
IF "%~1?" EQU "?" GOTO :EOF
SET "_window_title=%~1"
TASKLIST /FI "Status eq Running" /FI "Windowtitle eq %_window_title%" /FO "TABLE" | FINDSTR /c:"PID" > NUL && ( SET "is_running=1" ) || ( SET "is_running=0" )
SET "_window_title="
GOTO :EOF