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:

start ..\pgr1.exe  {First Program}
start ..\prg2.exe  {Second Program}

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 1 GOTO LOOP {Process not Found}

call Delayer5.exe {Wait 5 secconds}
start ..\prg1_pluginloader.exe {Program that needs prg1.exe to be active}

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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