I am just starting with batch and i am having a really hard time with my program. I want it to open a specific website in firefox in a new window. After some time this and only this window(so other Firefox Windows can run in the background) should close again. My program works when there is no other Firefox Window running but when another window is running my program doesn't work anymore. It opens the Website but then it stops. Can somebody help me? Please

@echo off
tasklist /V>%temp%\vor.txt
start firefox.exe
tasklist /V>%temp%\nach.txt
for /F "tokens=2 delims= " %%i in ('fc %temp%\vor.txt %temp%\nach.txt^|find "firefox.exe"') do set PID=%%i
echo PID: %PID%
del %temp%\vor.txt
del %temp%\nach.txt
TASKKILL /PID %PID% /T /F