Share this page 

Detect if a process is running then start it if notTag(s): Misc Prog HowTo


@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
REM adapt the list below to match your need
SET EXE=(notepad.exe wordpad.exe outlook.exe)
FOR %%i IN %EXE% DO (
    TASKLIST /NH /FI "IMAGENAME EQ %%i" 2%gt;NUL | FIND /I /N "%%i"%gt;NUL
    IF !ERRORLEVEL! EQU 0 ( CALL :ProcessFound %%i ) ELSE ( CALL :ProcessNotFound %%i )
)

ECHO Done.
EXIT /B 0

:ProcessFound
ECHO %1 is running
EXIT /B 0

:ProcessNotFound
ECHO %1 is not running
REM uncomment the line below to start a not-found process
REM START %1
EXIT /B 1