Hac*_*koo 4 vbscript batch-file batch-processing
我想检查进程是否正在运行?如果进程没有运行,那么我执行它(在这个例子中我带了进程名称= calc.exe的计算器)我启动了批处理脚本,但我有一个语法问题我相信!
@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
Run Code Online (Sandbox Code Playgroud)
这是使用代码作为基础的另一种方法:
@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
Run Code Online (Sandbox Code Playgroud)