I want to check if a process is running or not ? if the process is not running, then i execute it (in this example I took the calculator with process name = calc.exe) I started the batch script, but I have a syntax problem I believe !
@echo off
Set MyProcess=calc.exe
echo %MyProcess%
pause
for /f "tokens=1" %%i In ('tasklist /NH /FI "imagename eq %MyProcess%"') do set ff=%%i
echo %ff%
If /i %ff%==%MyProcess% (Echo %ff% est en cours d^'execution) Else (Start %MyProcess%)
pause
Here's another way to do it using your code as a base:
@echo off
Set "MyProcess=calc.exe"
echo "%MyProcess%"
tasklist /NH /FI "imagename eq %MyProcess%" 2>nul |find /i "%MyProcess%" >nul
If not errorlevel 1 (Echo "%MyProcess%" est en cours d^'execution) else (start "" "%MyProcess%")
pause
You may try like this:
tasklist /FI "IMAGENAME eq calc.exe" 2>NUL | find /I /N "calc.exe">NUL
if "%ERRORLEVEL%"=="0"
echo Running
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With