How do I add a countdown clock in a dos loop?

April 23, 2009 at 11:08:08
Specs: Windows XP
My color printer is shared, and it's a mighty popular printer! Trouble is, the client's session does not terminate once the print job is done. And I'm limited to 10 sessions. If 10 people send print jobs, the 11th won't print. (That's a problem for another forum...but on with the story.) I got used to leaving the Computer Management, Sessions window open and occasionally disconnecting all sessions. But I got tired of doing that. So, I wrote a batch file, below. It works OK, but when I look at it while running, I'd like to know how soon until it runs again. And I'm having trouble figuring that one out. I'd like to echo "Seconds until program runs again: " followed by the seconds remaining. TIA


@echo off
title End all sessions every 60 seconds.
net session /delete /y
ping 1.1.1.1 -n 1 -w 60000 >nul
%0



See More: How do I add a countdown clock in a dos loop?

Report •


#1
April 23, 2009 at 13:39:07
Something along these lines

@echo off
set i=60
for /L %%j in (1 1 60) do (
call :DisplayProgressBar %i%
ping -n 2 0.0.0.0 > NUL
set /a i = i - 1
)
net session /delete /y
GOTO :eof
:DisplayProgressBar
title Exit in %i%
exit /b


Report •

#2
April 23, 2009 at 14:33:52
if you prefer a graphic progress bar, copy and paste the following; never mind the exotheric chars as in the text window the ASCII rendering would be fine.

@echo off & setlocal EnableDelayedExpansion
title End all sessions every 60 seconds.
:LOOP
  cls
  net session /delete /y
  echo.
  echo.
  echo.    0   10   20   30   40   50    60
  echo.    ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄ´
  set /P pBAR=     < nul
  for /L %%j in (1,1,6) do (
  ping 1.1.1.1 -n 1 -w 10000 > nul
  set /P pBar=!pBar!ÛÛÛÛÛ< nul
  )
goto :LOOP


Report •

#3
April 23, 2009 at 14:47:28
I like that IVO. Can always join the 2

@echo off & setlocal EnableDelayedExpansion
title End all sessions every 60 seconds.
:LOOP
cls
set i=60
::net session /delete /y
echo.
echo.
echo. 0 10 20 30 40 50 60
echo. ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄ´
set /P pBAR= < nul
for /L %%j in (1,1,6) do (
call :DisplayProgressBar %i%
ping 1.1.1.1 -n 1 -w 10000 > nul
set /P pBar=!pBar!ÛÛÛÛÛ< nul
set /a i = i - 10
)
goto :LOOP
:DisplayProgressBar
title Exit in %i%
exit /b


Report •

Related Solutions

#4
April 24, 2009 at 05:49:51
Thank you. The following is what works best for me:

@echo off
net session /delete /y
set i=60
for /L %%j in (1 1 60) do (
call :DisplayProgressBar %i%
ping 0.0.0.0 -n 2 > NUL
set /a i = i - 1
)
cls
:DisplayProgressBar
title End all sessions - Run again in approx %i% seconds
%0


Report •


Ask Question