Delay a Batch command

Discussion in 'Web Design & Coding' started by the_tazinator, Feb 18, 2004.

  1. the_tazinator

    the_tazinator Are we there yet?

    Messages:
    177
    Location:
    In a house
    I am trying to write a batch file that will start a service 1 minute after a computer boots up. I have it set as a scheduled task to run at startup but I need to put a delay in it so that everything else has started before this process starts. Any ideas on how to create a simple 60 second delay?
     
  2. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
  3. the_tazinator

    the_tazinator Are we there yet?

    Messages:
    177
    Location:
    In a house
    I found a round-about way of creating the delay, but for anyone who wants to know how I did it; I pinged and invalid IP address once with a timeout of 60 seconds, works perfect!

    ping 1.1.1.1 -n 1 -w 60000

    This way the time delay can be easily be changed.
     
  4. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    Nice work around, i'll have to remember that :)
     
  5. yoyo

    yoyo _________________

    Messages:
    1,557
    Agreed, nice workaround.

    Alternatively you could use sleep.exe from the Windows Server 2003 (and XP) Resource Kit Tools.
    In case you don't want to download 12 MB to get a 5 KB file, find it attached. Unzip into your system32 folder. Now a line like
    Sleep 10
    will pause a batch file for ten seconds.
     

    Attached Files:

  6. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Hmmm, sleep was first introduced for BSD/Linux :p