+ Reply to Thread
Results 1 to 8 of 8

Thread: Simple Batch Question...

  1. #1
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Simple Batch Question...

    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 by Twinkie; 03-16-2009 at 04:51 PM.

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Simple Batch Question...

    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.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Simple Batch Question...

    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 by Twinkie; 03-16-2009 at 04:52 PM.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Simple Batch Question...

    2 things: remove the spaces around the equals sign in the first set command and use timeout rather than the busywait.

  5. #5
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Simple Batch Question...

    I don't know what the second thing you said meant, but removing the spaces works, thanks XD

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Simple Batch Question...

    Quote Originally Posted by Twinkie View Post
    I don't know what the second thing you said meant, but removing the spaces works, thanks XD
    Rather than looping (basically a busywait), use "timeout /T %secs%". Did you read the link I posted?

  7. #7
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Simple Batch Question...

    timeout doesn't work on xp or vista
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Simple Batch Question...

    Quote Originally Posted by garrettroyce View Post
    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.

+ Reply to Thread

Similar Threads

  1. Just a simple one question
    By brweb in forum Free Hosting
    Replies: 2
    Last Post: 03-22-2008, 11:59 PM
  2. Simple Navigation Design Question
    By MikeHGA79 in forum Programming Help
    Replies: 3
    Last Post: 12-29-2007, 11:57 AM
  3. Can anyone help me? Its a simple Question
    By CageFreak in forum Free Hosting
    Replies: 2
    Last Post: 10-21-2006, 11:47 PM
  4. Simple Ad Question
    By Death in forum Free Hosting
    Replies: 4
    Last Post: 02-14-2006, 04:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers