I am trying to just see if an application is currently running based on the Image Name in the task manager or tasklist... I am using firefox.exe as the example but it always fails. The goal is to not launch another script if its already running and/or to taskkill it when we need.
This is my current status script:
@echo off
set STATUS=
FOR /F "tokens=*" %%A IN ('tasklist ^| findstr "firefox.exe"') DO SET STATUS=%%A
echo %STATUS%
if [%STATUS%]==[] set STATUS=stopped
echo %STATUS%
Always gives the following output: (it always fails on the if statement)
firefox.exe 6216 Console 1 411,760 K
6216 was unexpected at this time.
Do you have an idea why this is or suggest another way to go about achieve this?