Simple Batch Question...

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
I have a little program I made to time a shutdown because Vista has a 10 minute limit to the shutdown time (in XP the limit it more than 6977 or so years XD).
Code:
@echo off
title Shutdown Timer
color 0c
set /p sec = "Enter amount of seconds: "

:LOOP
echo %sec%
ping localhost -n 2 > nul
set /a sec=%sec%-1
cls

if (%sec%-30==0) (
shutdown /s /t 30
) ELSE (
goto LOOP
)
It pauses, writes "echo is off" and then counts down from 0. Whats wrong with this??
 
Last edited:

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
set /a sec = %sec%-1

I think this should be:
set /a sec = %sec% + 1

Although not required, I also think it would be good to give %sec% an initial value of 0.
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Thank you for the suggestion, but this is supposed to be a countdown timer from a certain number of seconds until the computer shuts down. Changing the plus to a minus changes the effect, but it is still incrementing from 0 instead of the number specified. Thank very much for your help!

BTW: Nice avatar, I have a dog just like it ^^
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
2 things: remove the spaces around the equals sign in the first set command and use timeout rather than the busywait.
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
I don't know what the second thing you said meant, but removing the spaces works, thanks XD
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
timeout doesn't work on xp or vista

timeout works just fine for me in Vista. It doesn't exist under XP, but the poster doesn't need it for XP. If he did, he could get sleep from the Win23K resource kit tools and use that.
 
Top