Computing.Net > Forums > Programming > Count down Batch Script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Count down Batch Script

Reply to Message Icon

Name: CR
Date: December 11, 2008 at 04:57:22 Pacific
OS: Windows XP Pro SP3
CPU/Ram: AMD XP 2500+ 1GB
Product: Custom / CUSTOM BUILD
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: December 11, 2008 at 05:17:14 Pacific
Reply:

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


0

Response Number 2
Name: CR
Date: December 11, 2008 at 05:39:59 Pacific
Reply:

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 :)


0

Response Number 3
Name: Judago
Date: December 11, 2008 at 05:49:39 Pacific
Reply:

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.


0

Response Number 4
Name: CR
Date: December 11, 2008 at 06:05:40 Pacific
Reply:

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


0

Response Number 5
Name: Judago
Date: December 11, 2008 at 06:18:43 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: BatchFreak
Date: December 11, 2008 at 06:31:18 Pacific
Reply:

Why not just use Ping? for a 15 second delay

I only Batch if possible, 2000 more lines of code, oh well.


0

Response Number 7
Name: Holla
Date: December 11, 2008 at 22:31:29 Pacific
Reply:

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.


0

Response Number 8
Name: CR
Date: December 12, 2008 at 15:55:24 Pacific
Reply:

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 
@ECHO 

Shutdown -r -f -t 0
EXIT

The 3 @ECHO  commands at the end give off 3 beeps :)

Again, thank you all for your replies :)


0

Response Number 9
Name: saadia
Date: December 20, 2008 at 02:53:28 Pacific
Reply:

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?


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Count down Batch Script

Need Help With Batch Script www.computing.net/answers/programming/need-help-with-batch-script/9053.html

Editing a Hex file using a Batch script www.computing.net/answers/programming/editing-a-hex-file-using-a-batch-script/19381.html

batch script to parse filenames www.computing.net/answers/programming/batch-script-to-parse-filenames/15286.html