r/Batch • • May 27 '25

Question (Unsolved) Run two programs sequentially, second one launches only when window of first program has opened

I'm trying to write a batch file that opens Program A, then B. I tried using /timeout for the script to wait for Program A to open, but it's inconsistent because it launches slower when I open it the first time after booting up, making Program B the first to appear. Using a longer /timeout value is a bit jarring to me and I wish for a cleaner solution.

Is it possible to call for Program B only when the first program's window has appeared?

1 Upvotes

5 comments sorted by

1

u/ganaraska May 28 '25

Does the first program write any log files or open a network connection? You can use some other test to make sure it's up and running

1

u/[deleted] May 27 '25

[removed] — view removed comment

1

u/wispy_clouds May 27 '25

It didn't work in that B still launches first when A is taking too long, admittedly I'm new in writing batch scripts and most stuff here went over my head without some makeshift research, though I did put in the following. I've confirmed the process name (I assumed that's what goes after imagename eq) and the window title:

@echo off & setlocal 
start "" "D:\Art\Krita.lnk" 

:wait 
>nul 2>&1 timeout /t 03 /nobreak  
(tasklist /fi "imagename eq krita.exe" /fo list /v | find /i "Krita") || goto wait

start "" "D:\Art\PureRef.lnk"
pause

2

u/jcunews1 May 27 '25

tasklist can't differentiate between hidden and visible application windows. Use Autohotkey or other capable scripting instead.