Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I am trying to count down from 15 to 1 using a batch script under Windows XP Pro SP3 but can't quite get it to work...
This is what I have at the moment:
SET COUNTDOWN=15
:COUNTDOWNLOOP
IF %COUNTDOWN%==0 GOTO END
ECHO Rebooting in %COUNTDOWN% seconds... && %R1%
CLS
SET /A COUNTDOWN -=1
GOTO COUNTDOWNLOOP
:END
Shutdown -r -f -t 0%R1% is simply a 1 second pause using the following: SET R1=Start /w Commands/Rest1.vbs
The contents of the Rest1.vbs file are as follows: Wscript.sleep 875

It seems to work fine for me, a less cluttered way to do things may be:
@echo off
SET R1=Start /w Rest1.vbs
cls
for /l %%a in (15,-1,1) do (
ECHO Rebooting in %%a seconds...
%R1%
cls
)
Shutdown -r -f -t 0

Thank you for your version, it works just as required ;) However, I do not understand why my original code did not work... It just closed the CON.
Any feedback on why it would do this?
Thank you again for your super fast reply by the way :)

To be honest I can't see anything obvious that would cause that in this script other than a variable containing something unexpected, like a redirection > symbol.
One very useful method of trouble shooting these scripts that close unexpectedly is to start them from a cmd window rather than clicking on them in explorer. By this I mean start up a command prompt start>run>cmd then navigate to the directory your batch is in then type in the file name of your batch. This way you will be able to read the error it spits out after the batch ends.

Good tip thanks for that - prev I have simply been turning echo back on and adding a pause command to the end of the batch but as I'm sure you know, this method is ok until there is an error in the middle of the script lol
Anyway, thanks again for the countdown script :) It saved me repeating 15 of the same 'Rebooting in xx seconds...' with a pause and a CLS in between :P

Pause and echo are, in my opinion, the most valuable commands when it comes to trouble shooting, so I think your on the right track...
Glad I could be of some assistance.

Why not just use Ping? for a 15 second delay
I only Batch if possible, 2000 more lines of code, oh well.

Well, old XP's shutdown used to display a countdown for the command "shutdown -s -t 15"
Serving the purpose CR.
Now this is vanished in Vista.may be if the old xp's shutdown.exe can be used ?
--
Holla.

Hi BatchFreak, thanks for your reply - problem was that I needed the user to see the count down on screen and not mearly pause for 15 seconds but thanks anyway ;)
Hi Holla, thanks for your reply too but you kind of answered your own question in your reply :) You see, this batch file needs to work on not only Windows XP but also on Windows Vista too hence I could not use the standard shutdown -s -t 15 command.
I have it sorted now tho peeps and am using Judago's code.
This is what I have:
CLS
for /l %%a in (15,-1,1) do (
ECHO.
ECHO Reboot Required
ECHO.
ECHO AUTO REBOOT IN %%a SECONDS
cls
)CLS
COLOR 4F
ECHO.
ECHO SYSTEM REBOOTING
ECHO.
@ECHO
@ECHO
@ECHOShutdown -r -f -t 0
EXITThe 3 @ECHO commands at the end give off 3 beeps :)
Again, thank you all for your replies :)

hey, can anyone tell me how to display a countdown in visual basic? i'm trying to count down from 7-0 seconds...does anyone here knows the correct coding?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |