0

I have been trying to get this batch file to work but keep running into issues. I think I am close but need help getting this working. When the script runs I get Find: Parameter format not correct.

I am running this on a Windows Server 2008 R2 Standard.

@echo off 


tasklist /FI "IMAGENAME eq program.exe" | find /i “program.exe" 


IF ERRORLEVEL 2 GOTO NEXTPROGRAM

IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM


:NEXTPROGRAM

goto SMADMIN



:LAUNCHPROGRAM

start "" "C:\path\to\program.exe"

goto SMADMIN


:SMADMIN

tasklist /FI "IMAGENAME eq program1.exe" | find /i “program1.exe" 


IF ERRORLEVEL 2 GOTO NEXTPROGRAM2

IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM2


:NEXTPROGRAM2

goto COMPLETE



:LAUNCHPROGRAM2

start "" "C:\path\to\program1.exe"

goto COMPLETE
jimrice
  • 452
  • 5
  • 17
  • 1
    The posted code includes a wrong quote in the `find` commands. Is it a typo error or does your code really include it? – MC ND Feb 12 '15 at 08:05
  • 1
    You'd need to write your code using a text editor (like notepad, notepad++, EditPlus, etc) not a word-processor because WPs will use "smart quotes" and they're too smart for `CMD` – Magoo Feb 12 '15 at 08:11
  • MC, please transform your comment into an answer – PA. Feb 12 '15 at 08:18
  • They should not have been those quotes. Appears to have been an issue with the editor I was using. Works fine now. Thank you – jimrice Feb 13 '15 at 03:27

1 Answers1

1

You can check whether the exe is running this way:

SET running=0
FOR /f "tokens=*" %%A IN ('tasklist^ /v^| findstr /i /c:"program.exe"') DO SET running=1
IF %running%=1 GOTO NEXTPROGRAM
IF %running%=0 GOTO LAUNCHPROGRAM

Afterwards you just have to check if the %ProgramRunning% is set to 1.

Don't forget to reset the %running% flag back to 0 before reusing it.

MichaelS
  • 5,941
  • 6
  • 31
  • 46