0

I use a batch file to countdown and need to stop this countdown process in another batch file.

  • I've tried to use these, but they all failed:
    taskkill /f /fi "windowtitle eq countdown"
    taskkill /f /im countdown.cmd
    taskkill /f /fi "windowtitle eq counting down"
    
  • countdown.cmd:
    Title %~n0
    color 4F
    
    @echo off
    mode 32,10
    
    title Timer
    
    echo Enter time to countdown from.
    set time=233
    
    :loop
    cls
    
    set /a time=%time%-1
    if %time%==0 goto timesup
    
    title Counting down...
    
    echo.
    echo.
    
    echo.
    echo Countdown - [%time%]
    
    ping localhost -n 2 > nul
    goto loop
    
    :timesup
    echo Time is Up!
    start %~dp0FocusApp.cmd
    goto end
    
    :end
    @exit
    
8
  • What error messages do you get when trying the commands? Do you get any, or does it just not work?
    – yrjarv
    Commented May 19, 2022 at 9:36
  • "No tasks running with the specified critera"
    – VB88
    Commented May 19, 2022 at 9:46
  • "error: The process "countdown.cmd" not found."
    – VB88
    Commented May 19, 2022 at 9:47
  • Judging from the picture and the code, the WindowTitle is Administrator: countdown respectively Administrator: Counting down..., not countdown, and the Image is cmd.exe, not countdown.cmd . Better find the PID with tasklist /v | find "Counting down..." with a for /f "tokens=2"` loop and then taskkill /PID
    – Stephan
    Commented May 19, 2022 at 11:20
  • Hi I am able to find the PID in separate command but when putting them together like this but shows error. Please help to rectify this script : FOR /f "token=2 %%i in (tasklist /v | find "Counting down...") do taskkill /pid %%i
    – VB88
    Commented May 19, 2022 at 14:56

1 Answer 1

2

Place a * at the end of windowtitle for Windows to append something to the Window Title at process start:

taskkill /f /fi "windowtitle eq countdown*"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .