[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2014-08-29
Medium Priority
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
  • 3
  • 2
LVL 85

Accepted Solution

oBdA earned 2000 total points
ID: 40293374
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

ID: 40293589
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 85

Expert Comment

ID: 40293596
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.
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments


Author Comment

ID: 40293636
Works well now. Thank you.
LVL 43

Expert Comment

by:Steve Knight
ID: 40293905
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

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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Suggested Courses

872 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