本文介绍了检查进程是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个进程是否正在运行?如果该进程未运行,则执行它(在本示例中,我使用了进程名称为calc.exe的计算器)我启动了批处理脚本,但是我相信我有语法问题!

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

这篇关于检查进程是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 11:55