Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am currently trying to create a batch file that launches some programs for me. This could easily be done with the command "start" but the last program it runs only works if the first one's window is active.

I have tried using a delay before the last program. But the first one does not use the same starting delay everytime, making me need sometimes a long delay or a short one.

So I thought I had to make the code wait for the process to be running and added a line of code to do so. But sometimes the first program has its process running without having the window active (in long delay situations mentioned above) so the delay ends and the last program fails to start.

Now i show how my batch file looks so far:

@ECHO OFF
start ..\pgr1.exe  {First Program}
start ..\prg2.exe  {Second Program}

:LOOP
C:\Windows\System32\tasklist.exe /FI "IMAGENAME eq prg1.exe" |  {Get Tasklist}
C:\Windows\System32\find.exe /i "prg1.exe" {Find First Program Process}
IF ERRORLEVEL 2 GOTO ROLL {Process Found}
IF ERRORLEVEL 1 GOTO LOOP {Process not Found}

:ROLL
call Delayer5.exe {Wait 5 secconds}
start ..\prg1_pluginloader.exe {Program that needs prg1.exe to be active}
cls
share|improve this question

1 Answer 1

You could still use tasklist.exe like so:

tasklist.exe /FI "IMAGENAME eq prg1.exe" /V | findstr "Your Window Title"

/V will print the window title of the window associated with the process, so you can use that check to control your loop.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.