I have multiple processes by the same name (say multiple FIREFOX.exe process). A Batch script then opens another firefox.exe process and, after some predefined time, needs to kill the process it opened.
I had the following solution for it
start "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -P "ABC" -no-remote PING 127.0.0.1 -n 10 -w 1000 >NUL for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq firefox.exe"') do set MyPID=%%b taskkill /PID %MyPID% /T
This works fine EXCEPT if another process by the same name (firefox.exe) opens after the 1st command (i.e running firefox), the taskkill command actually kills the latest process instead of the one it started
So how do i make sure the script only kills the process it started and none other.