Search code examples
batch-filetasklisttaskkill

Close all firefox tabs with BATCH


I try to close all firefox if there are more than one. I want to do loop that check the firefox process and close and check again until there is no any firefox process.

This is my code:

:loop
taskkill /im "firefox.exe"
tasklist /fi "imagename eq firefox.exe" goto loop

Where is my wrong in this command ? Any help is appreciated.


Solution

  • :loop 
    tasklist /fi "imagename eq firefox.exe" | find "firefox.exe" >nul && ( taskkill /im firefox.exe >nul & goto loop )
    

    Get list of tasks, and if firefox.exe included in it, then kill it and goto loop