How do I display elapsed time in a pop up window?

Posted on 2014-08-29
Last Modified: 2014-09-02
I have the following in a batch script:

REM Launch the message "window"
start "** RUNNING **" m.bat

The m.bat file looks like this:

@echo off
echo ****************************************
echo ****************************************
echo ****     BATCH PROCESS RUNNING      ****
echo ****            DO NOT END          ****
echo ****************************************
echo ****************************************
pause > null

I would like somehow to display the elapsed time as well.
In other words how much time has gone by from when the script was run?
A count up timer, ie   2 minutes, 45 seconds.. and it keeps counting up.
Question by:100questions
    LVL 82

    Accepted Solution

    On which OS, and is it important/required that the script can be closed by pressing a key?
    The "m" script could probably even monitor the main script and then end itself when the main script ends, but for that, you need to provide more information about the calling script.
    In the meantime, how about something like this (it uses choice.exe; should be part of Windows since Vista):
    @echo off
    set /a Interval = 5
    set /a Seconds = 0
    echo ****************************************
    echo ****************************************
    echo ****     BATCH PROCESS RUNNING      ****
    echo ****            DO NOT END          ****
    echo ****************************************
    echo ****************************************
    echo ** RUNNING for %Seconds% seconds **
    set /a Seconds += Interval
    choice.exe /t 5 /d C /n /c CX >NUL
    if %errorlevel%==1 (
    	title ** RUNNING for %Seconds% seconds **
    	goto Loop
    exit /b

    Open in new window


    Author Comment

    Thank you.  
    OS is Windows 8.
    Another script which runs will need to kill the m.bat process.
    It looks like at the moment that script does not kill the process however, and the m.bat just keeps running and running.

    My other script had this near the end of the script which would kill the m.bat script, however this no longer works:

    REM Find and kill the message proc
    for /f "tokens=2 delims=," %%A in ('tasklist /v /fo csv ^| find "** RUNNING **"') do (
      taskkill /pid %%~A > nul

    Any suggestions?

    Thanks in advance.
    LVL 82

    Expert Comment

    Then the other script probably looks for Window title, which I used to display the remaining time as well.
    Remove line 17 and try again.

    Author Comment

    Works well now. Thank you.
    LVL 43

    Expert Comment

    by:Steve Knight
    Sometimes useful to add a change of window size and color too if wanted, add something like this below @echo off:

    mode 45,10
    color 4f

    color  /? shows you color possibilities.  mode is cols,rows


    Author Comment

    Thanks dragon-it, very useful features.   I tried it and it works well.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Windows 10 upgrade issues 11 60
    Building Windows 10 1 52
    Turbo stick question 4 26
    How to upgrade Windows 8 Pro to 8.1 Pro 6 36
    Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
    If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now