sc query|findstr /i "ZhuDongFangYu" &&echo "存在" ||echo "不存在"
:: Form https://www.cnblogs.com/xiongzaiqiren @echo off rem 右键:以管理员身份运行 set ServiceName=Redis :ExistOrNotByServiceName1 @echo 检查是否有服务%ServiceName%? for /f "skip=3 tokens=1" %%i in ('sc query %ServiceName%') do set "zt=%%i" &goto :ExistOrNotByServiceName2 :ExistOrNotByServiceName2 echo "%zt%" if /i "%zt%"=="STATE" ( echo 服务 %ServiceName% 存在。 ) else ( echo 服务 %ServiceName% 不存在! ) :end pause
sc query "ZhuDongFangYu" |findstr /i "RUNNING" >nul &&echo "状态运行中" ||echo "状态非运行"
:: Form https://www.cnblogs.com/xiongzaiqiren @echo off rem 右键:以管理员身份运行 set ServiceName=Redis :StateByServiceName1 @echo 检查服务%ServiceName%运行状态: for /f "skip=3 tokens=4" %%i in ('sc query %ServiceName%') do set "zt=%%i" &goto :StateByServiceName2 :StateByServiceName2 echo "%zt%" if /i "%zt%"=="RUNNING" ( echo 服务%ServiceName%运行中。 ) else ( echo 服务%ServiceName%是未运行状态。 ) :end pause
netstat -ano|findstr 3390 >nul &&echo "存在端口。" ||echo "不存在端口。"
tasklist|findstr /i "chrome.exe">nul &&echo "存在进程。" ||echo "不存在进程。"
【完】