Batch file is executing wrong variable - batch-file

Having a latency less than 600 but greater than 90 continues to go to :FAST CONNECTION. It should be going to :MODERATE CONNECTION.
#ECHO off
MODE CON:cols=38 lines=11
:LOOP
SET a=3000
FOR /f "tokens=7 delims== " %%G IN ('PING -4 -n 1 8.8.8.8^| FIND "TTL" ') DO SET a=%%G
CLS
IF %a% EQU 3000 (GOTO :NO CONNECTION) ELSE (GOTO :SPEED)
:SPEED
IF %a% GTR 600 (GOTO :SLOW CONNECTION)else (IF %a% LSS 90 (GOTO :FAST CONNECTION) else (GOTO :MODERATE CONNECTION))
TIMEOUT /T 2 > NUL
:NO CONNECTION
COLOR 4F
ECHO.
ECHO.
ECHO --- NO CONNECTION ---
ECHO.
ECHO CHECK YOUR NETWORK CONNECTION
TIMEOUT /T 2 > NUL
CLS
ECHO.
ECHO.
ECHO *** NO CONNECTION ***
ECHO.
ECHO CHECK YOUR NETWORK CONNECTION
TIMEOUT /T 2 > NUL
CLS
ECHO.
ECHO.
ECHO !!! NO CONNECTION !!!
ECHO.
ECHO CHECK YOUR NETWORK CONNECTION
TIMEOUT /T 2 > NUL
GOTO :END
:FAST CONNNECTION
COLOR 2F
ECHO.
ECHO YOU CURRENTLY HAVE A
ECHO FAST CONNECTION TO INTERNET: %a%
ECHO.
ECHO APPLICATIONS AND FILE TRANSFERS
ECHO WILL RUN AT A GREAT RATE
ECHO.
ECHO FAST 0 - 10
ECHO MODERATE 11 - 20
ECHO SLOW 600 - 3000
TIMEOUT /T 3 > NUL
GOTO :END
:MODERATE CONNECTION
COLOR 6F
ECHO.
ECHO YOU CURRENTLY HAVE A
ECHO MODERATE CONNECTION TO THE INTERNET : %a%
ECHO.
ECHO APPLICATIONS AND FILE TRANSFERS
ECHO WILL RUN AT A SO/SO RATE
ECHO.
ECHO FAST 0 - 10
ECHO MODERATE 11 - 20
ECHO SLOW 600 - 3000
TIMEOUT /T 3 > NUL
GOTO :END
:SLOW CONNECTION
COLOR 4F
ECHO.
ECHO YOU CURRENTLY HAVE A
ECHO SLOW CONNECTION TO INTERNET: %a%
ECHO.
ECHO ALTERNATE OR CONTINGENCY
ECHO NETWORK WILL RUN AT A SLOWED RATE
ECHO.
ECHO FAST 0 - 10
ECHO MODERATE 11 - 20
ECHO SLOW 600 - 3000
TIMEOUT /T 3 > NUL
GOTO :END
:END
GOTO :LOOP

FOR /f "tokens=7 delims== " %%G IN ('PING -4 -n 1 8.8.8.8^| FIND "TTL" ') DO SET a=%%G
On a US-EN machine a gets set to a number with the time unit ms appended e.g. 100ms.
This causes the following comparisons to work as string comparisons (lexicographically), not number comparisons, so for example:
C:\etc>if 100ms LSS 11 #echo ???
???
C:\etc>if 100ms LSS 10 #echo ???
C:\etc>
The quick-and-dirty solution in this case is to strip the ms suffix right after the for loop.
set "a=%a:~0,-2%"
Note: this may not - and will likely not - work on localized Windows other than US-EN.

For the purpose of this demonstration, I've set a timeout of 3 seconds at the end of the script, you can adjust this as you please.
Your main issue is that you are using labels with spaces, you cannot do that. Second issue is that, as already mentioned by #Mofi in a comment, depending on your keyboard settings (language) different items are assigned to %a%.
I however suggest that you do 2 pings and use the average result, instead of ttl.
As a side note, ping (using ICMP) is for diagnostics and will not always get priority.
#echo off
MODE CON:cols=38 lines=11
:test
set latency=3000
#echo off
for /f "tokens=2delims==, " %%i in ('ping -4 -n 2 8.8.8.8^| find /i "average" ') do set "latency=%%i"
set latency=%latency:ms=%
if %latency% gtr 600 if %latency% lss 3000 (
color 4F
echo(
echo Slow connection %latency%
echo(
)
if %latency% geq 3000 (
color 4F
echo(
echo Connection seems down %latency%
echo(
)
if %latency% lss 90 (
color 2F
echo(
echo Fast Connection %latency%
echo(
)
if %latency% gtr 90 if %latency% lss 600 (
color 6F
echo(
echo Moderate Connection %latency%
echo(
)
(timeout /t 3)>nul 2>&1 & cls & goto test
You will note, for obvious reasons I removed some of the noise you had, you can add all the echo( back if you want, but I do not see the purpose of it. I also removed all the goto labels, as it is not required.

Please begin by taking note of my comment, which tells you that this code will not provide a measurable indication of your internet connection's speed.
Now, without radically changing your script and layout, you could probably use wmic with Win32_PingStatus, instead on ping. This should ensure that your variable always has the response time in milliseconds, if one is returned within the allowed timespan:
Example, (Just change the Host Address on line 5 as needed):
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Mode CON:Cols=45 Lines=11
Set "HA=8.8.8.8"
:Loop
Color
Set "RT="
For /F EOL^=R %%G In ('%__AppDir__%wbem\WMIC.exe Path Win32_PingStatus Where^
"Address='%HA%'" Get ResponseTime 2^>NUL')Do For %%H In (%%G)Do Set "RT=%%H"
If Not Defined RT GoTo None
If %RT% Gtr 600 GoTo Slow
If %RT% Gtr 90 GoTo Moderate
:Fast
Color 2F
Echo=
Echo YOU CURRENTLY HAVE A
Echo FAST CONNECTION TO INTERNET: %RT%ms
Echo=
Echo APPLICATIONS AND FILE TRANSFERS
Echo WILL RUN AT A GREAT RATE
Echo=
Echo FAST : 0 - 10
Echo MODERATE : 11 - 20
Echo SLOW : 600 - 3000
Echo=
%__AppDir__%timeout.exe /T 5 /NoBreak >NUL
GoTo Loop
:Moderate
Color 6F
Echo=
Echo YOU CURRENTLY HAVE A
Echo MODERATE CONNECTION TO THE INTERNET: %RT%ms
Echo=
Echo APPLICATIONS AND FILE TRANSFERS
Echo WILL RUN AT A SO/SO RATE
Echo=
Echo FAST : 0 - 10
Echo MODERATE : 11 - 20
Echo SLOW : 600 - 3000
Echo=
%__AppDir__%timeout.exe /T 5 /NoBreak >NUL
GoTo Loop
:Slow
ClS
Color 4F
Echo=
Echo YOU CURRENTLY HAVE A
Echo SLOW CONNECTION TO INTERNET: %RT%ms
Echo=
Echo ALTERNATE OR CONTINGENCY NETWORK
Echo WILL RUN AT A GREAT RATE
Echo=
Echo FAST : 0 - 10
Echo MODERATE : 11 - 20
Echo SLOW : 600 - 3000
Echo=
%__AppDir__%timeout.exe /T 5 /NoBreak >NUL
GoTo Loop
:None
ClS
Color 4F
Echo=
Echo --- NO CONNECTION ---
Echo=
Echo CHECK YOUR NETWORK CONNECTION
Echo=
%__AppDir__%timeout.exe /T -1
GoTo Loop
Please be aware, that I do not know why you've asked the code to loop back to the ping, so if that's not your overall intention, for now you'll need to use CTRL+C to stop if from looping.

Related

Batch program unexpected when I type something

Ok, so I've made a batch game and I'm writing through the tutorial right now. My plan is to make %roll%
set /a roll=(%random% %% 7) + 1
Capable of taking away %enhealth% and %yourhealth%
:foresttutorial
cls
echo.
echo __________________________
echo | |
echo | An enemy appeared! |
echo | Enemy health: %enhealth% |
echo | Your health: %yourhealth%|
echo | |
echo | 1. ATK 2. USE POT |
echo | 3. GOLD 4. PASS |
echo | _________________________|
echo.
echo Here appears an attack screen!
echo Quick, press 1 and enter!
set /p choice8
if %choice8% == 1 goto atkforesttutorial1 else goto invalidforesttutorial1
:invalidforesttutorial1
cls
echo Invalid answer. You can try the other options soon,
echo for now just press 1.
pause
goto foresttutorial
:atkforesttutorial1
set /a roll=(%random% %% 7) + 1
set enhealth = %enhealth% - %roll%
echo You attacked the enemy!
echo.
echo __________________________
echo | |
echo | An enemy appeared! |
echo | Enemy health: %enhealth% |
echo | Your health: %yourhealth%|
echo | |
echo | 1. ATK 2. USE POT |
echo | 3. GOLD 4. PASS |
echo | _________________________|
echo.
pause
Above is my code. When I type in 1 for the FIRST box, and click enter, it pops up with a flash that says "1 was unexpected..." or something similar. Any ideas on how to fix this?
Full code here:
https://pastebin.com/kBNgNV1G
I've made a few changes, some are fixes other's are hopefully to help you see a different way of doing things, *(primarily use of Choice /C for input selection and Call :label to minimize repeating echo'd text.
#Echo Off
If /I Not "%CD%"=="directoryForscreed" CD /D "directoryForscreed" 2>Nul||Exit/B
For %%A In ("premenupicture" "dice" "atkmenusample" "mainmenuforscreed"
) Do If Not Exist "%%A.txt" Exit/B
Title Forscreed
Color 07
Mode 80,25
:premenu
Echo=
Type premenupicture.txt
Echo=
Choice /C 123 /M "Please type in your choice number: "
If ErrorLevel 3 GoTo credits
If ErrorLevel 2 GoTo loadgame
If ErrorLevel 1 GoTo newgame
ClS
GoTo premenu
:newgame
Set/A "key=chest=level=rank=gold=playwon=playloss=enwon=enloss=dice=prestige=0"
Set/A "atk=def=int=vit=1"
Set "health=100"
:prologue
ClS
Echo Wake up..
Timeout 2 /NoBreak>Nul
ClS
Echo Wake up!
Timeout 2 /NoBreak>Nul
ClS
Call :prologEcho
Choice /C 1234
If ErrorLevel 4 GoTo tutorialfinish1
If ErrorLevel 3 GoTo caveprologue
If ErrorLevel 2 GoTo scavengeprologue
If ErrorLevel 1 GoTo prologueboat
GoTo prologue
:prologueboat
ClS
Call :prologueboatEcho
Choice /C 1234
If ErrorLevel 4 GoTo prologue
If ErrorLevel 3 GoTo prologuemast
If ErrorLevel 2 GoTo prologuecaptaincabin
If ErrorLevel 1 GoTo prologuedeck
GoTo prologueboat
:prologuedeck
ClS
Echo The deck is empty, except for a satchel. You reach inside and find a Rusty
Echo Pistol and equip it. You walk out off the deck.
Timeout -1
:prologueboat2
ClS
Call :prologueboatEcho
Choice /C 1234
If ErrorLevel 4 GoTo prologue
If ErrorLevel 3 GoTo prologuemast
If ErrorLevel 2 GoTo prologuecaptaincabin
If ErrorLevel 1 GoTo prologuedeck2
GoTo prologueboat2
:prologuedeck2
ClS
Echo Nothing here!
Timeout -1
GoTo prologueboat2
:prologuecaptaincabin
ClS
Echo The captain's cabin is tiny. Cramped up, you walk into the room. There is a
Echo bag of gold, a magazine for a pistol, and an old pair of boots. You walk out
Echo of the captain's cabin.
Timeout -1
:prologueboat3
ClS
Call :prologueboatEcho
Choice /C 1234
If ErrorLevel 4 GoTo prologue
If ErrorLevel 3 GoTo prologuemast
If ErrorLevel 2 GoTo prologuecaptaincabin2
If ErrorLevel 1 GoTo prologuedeck2
GoTo prologueboat3
:prologuecaptaincabin2
ClS
Echo Nothing here!
Timeout -1
GoTo prologueboat3
:prologuemast
ClS
Echo You climb up the mast. Nothing here! You can use the ropes though, so you
Echo take it off.
Timeout -1
:prologueboat4
ClS
Call :prologueboatEcho
Choice /C 1234
If ErrorLevel 4 GoTo prologue
If ErrorLevel 3 GoTo prologuemast2
If ErrorLevel 2 GoTo prologuecaptaincabin2
If ErrorLevel 1 GoTo prologuedeck2
GoTo prologueboat4
:scavengeprologue
ClS
Echo A dice appeared! What do you do with it? Shrugging, you put it in your pocket.
Echo (You can't scavenge anymore after this until you finish the tutorial!)
Set/A dice+=1
Timeout -1
:prologue2
ClS
Call :prologEcho
Choice /C 1234
If ErrorLevel 4 GoTo tutorialfinish1
If ErrorLevel 3 GoTo caveprologue
If ErrorLevel 2 GoTo scavengeprologue2
If ErrorLevel 1 GoTo prologueboat
GoTo prologue2
:scavengeprologue2
ClS
Echo Can't scavenge in the tutorial! Complete the tutorial first, then you can
Echo scavenge again.
Timeout -1
GoTo prologue2
:caveprologue
Cls
Echo You walk to the cave and find a warm fire lit up. How was it lit? You don't
Echo know. You quickly scramble to near the fire for warmth, satisfied.
Timeout -1
GoTo prologue
:tutorialfinish1
ClS
Echo You pull out what you found from your pockets. A rusty gun, a magazine for
the gun, and a dice. I wonder what the dice does?
Timeout -1
ClS
Echo The dice rolls in your hand, and you accidentally drop it. It glows golden!
Timeout -1
ClS
Timeout 1 /NoBreak>Nul
Type dice.txt
Echo=
Echo Rolling a 7-sided die...
Timeout 2 /NoBreak>Nul
Set/A roll=(%random% %% 7) + 1
Echo You landed a %roll%!
Timeout -1
ClS
Echo Your objective is to build up a boat to go find the artifacts which end the
Echo game. The game is frequently updated, so check on the website for more quests
Echo and islands, plus new artifacts. The main playing style is fighting,
Echo equipping, trading, buying, leveling, and surviving as best as you can.
Timeout -1
ClS
Type atkmenusample.txt
Echo This is what you'll get upon questing or fighting in the woods! Monsters drop
Echo food, which is what you need to survive. You lose health every time do you a
Echo task, an estimated 0.712 health taken. You can regain the health with food. To
Echo fight, you will normally type in 1 and attack. The golden dice will do
Echo everything for you! The formula consists of your strength, weapons, and the
Echo dice rolled.
Timeout -1
ClS
Echo Then, the enemy takes his turn to attack! The computer will calculate all of
Echo this for you, and deal in the damage. Press 2 to use a health potion, and
Echo press 3 to your gold. If you're feeling it, you can also pass your turn,
Echo allowing the enemy to go. Other that fighting, the game is really mainly about
Echo a mystery storyline, which often requires equipment, gold, and equipment from
Echo quests. You can level up tools this way too. One of the special things about
Echo Forscreed is that there are no "different" swords. It simply levels up your
Echo swords to deal more damage.
Timeout -1
ClS
Echo Let's give attacking a try!
Echo Travel to the main menu:
Timeout -1
:mainmenututorial
ClS
Echo Here we are, at the tutorial. When this tutorial ends, it should look a bit
Echo like this:
Echo=
Type mainmenuforscreed.txt
Echo=
Echo Above is the main menu. You're going to want to attack, so let's hit 1.
Choice /C 1
If Not Errorlevel 1 goto invalidmainmenututorial1
GoTo foresttutorial
:invalidmainmenututorial1
ClS
Echo Invalid answer. You can try the other options soon, for now just press 1.
Timeout -1
GoTo mainmenututorial
:foresttutorial
ClS
Echo=
Echo __________________________
Echo ^| ^|
Echo ^| An enemy appeared! ^|
Echo ^| Enemy health: %enhealth% ^|
Echo ^| Your health: %yourhealth%^|
Echo ^| ^|
Echo ^| 1. ATK 2. USE POT ^|
Echo ^| 3. GOLD 4. PASS ^|
Echo ^| _________________________^|
Echo=
Echo Here appears an attack screen! Quick, press 1!
Choice /C 1
If Not ErrorLevel 1 GoTo invalidforesttutorial1
GoTo atkforesttutorial1
:invalidforesttutorial1
ClS
Echo Invalid answer. You can try the other options soon, or now just press 1.
Timeout -1
GoTo foresttutorial
:atkforesttutorial1
ClS
Set/A roll=(%random% %% 7) + 1
Set/A enhealth-=roll
Echo You attacked the enemy!
Echo=
Echo __________________________
Echo ^| ^|
Echo ^| An enemy appeared! ^|
Echo ^| Enemy health: %enhealth% ^|
Echo ^| Your health: %yourhealth%^|
Echo ^| ^|
Echo ^| 1. ATK 2. USE POT ^|
Echo ^| 3. GOLD 4. PASS ^|
Echo ^| _________________________^|
Echo=
Timeout -1
Exit/B
:prologEcho
Echo The sea is glimmering.. A broken boat seems to have crashed against a huge
Echo wooden rod. A spiritual tomb of some sort! You remember now. The Queen of
Echo Walkers sent you on a mission to save the kingdom by finding an artifact on
Echo the other side of the world, but you faced a storm and crashed into this
Echo wooden tomb.
Echo=
Echo Night is falling quick, what will you do?
Echo 1. Go to the boat.
Echo 2. Scavenge for resources.
Echo 3. Look around that cave nearby, looks fishy.
Echo 4. I already did all of these.
GoTo :EOF
:prologueboatEcho
Echo You walk to the boat. It's broken at the side, so it can't be used. The
Echo material is also weak. It's been thrashed by heavy waves and can't sail.
Echo Where do you search on the boat?
Echo 1. The deck
Echo 2. The captain's cabin
Echo 3. The mast
Echo 4. Get off boat
GoTo :EOF

how do you make a simple clock in batch

I am wondering if I can make a moving clock without having to refresh. This is my current code:
:clks
cls
echo.
echo ======
echo %DATE%
echo %TIME%
echo ======
timeout -t 1 >nul
goto clks
Try this:
#echo off
setlocal EnableDelayedExpansion
for /L %%i in () do (
cls
echo/
echo ======
echo !DATE!
echo !TIME!
echo ======
timeout -t 1 > nul
)
This is an near real time clock, using the ping command to create an delay short enough to visualize the milliseconds.
#echo off
#mode con cols=25 lines=3
title Clock
color 0f
:loop
echo %date%
echo %time%
for /l %%I in (1,1,2) do ping -n 01 127.0.0.1 > nul
cls
goto loop
The first block of code is mostly just visual enhancements. The pure clock code is:
#echo off
:loop
echo %date%
echo %time%
for /l %%I in (1,1,2) do ping -n 01 127.0.0.1 > nul
cls
goto loop
Instabilities like flashing can be fixed by increasing the number of pings in the for loop (currently 2), just be aware that doing so will make the clock run less smoothly.
#echo off
:12
title %time%
goto 12

Need help coloring specific text in batch

I am trying to color specific parts of the text and have managed to succeed partially. I am using the call :colorEcho line to color the text. The line that doesn't work is line 72. It works the first time, in line 54, but not the next. I was just wondering if anyone here knows how to fix this.
BTW I got the code from here
#echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
:start
echo You have been studying for years for this moment, to create a human master race, all you have to do is complete the circuit connecting the lightning rods to the speciman. Do you do it?
ping -n 2 1.1.1.1 > nul
echo.
echo 1) Connect the circuit.
echo 2) No, you take your work and burn it.
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto awaken
if "%Choice%"=="2" goto end1
:awaken
cls
echo 3
timeout /t 2 /nobreak >nul
cls
echo 2
timeout /t 2 /nobreak >nul
cls
echo 1
timeout /t 2 /nobreak >nul
cls
echo CRACK!!
timeout /t 2 /nobreak >nul
cls
echo Lightning strikes the rod and you see movement coming from the speciman under the sheet on the table.
pause
cls
echo The creature sits up. It is more disgusting then you ever could have imagined, you are terrified. It stares at you with mindless eyes, what do you do?
echo.
echo 1) Run for your life.
echo 2) Stay in the Room.
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm
:run4life [
cls
]
:staycalm [
cls
echo The monster stares at you.
timeout /t 4 /nobreak >nul
echo It screams
timeout /t 1 /nobreak >nul
call :colorEcho 0a "RAAAAUUUGGGHHH"
timeout /t 2 /nobreak >nul
echo.
echo 1) Run for your life.
echo 2) Stay in the Room.
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm2
]
:staycalm2
[
cls
timeout /t 3 /nobreak >nul
echo You hear a knock at the door.
call :colorEcho 0a " Hello, anyone there? Someone reported hearing a scream from your residence."
echo.
echo How should you react?
echo.
echo 1) Jump out the window.
echo 2) Answer the door.
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm3
]
:staycalm3
[
cls
call :colorEcho 0c "Oh yes, I was just scared by a spider."
echo.
timeout /t 2 /nobreak >nul
echo.
call :colorEcho ob "uhhmmm..."
timeout /t 2 /nobreak >nul
echo.
echo.
call :colorEcho 0b "Well, do you mind if I come in just to check around?
]
:end 1
cls
echo Congratulations, you have completed the game without causing anyone to die!
echo.
echo 1) Exit
echo 2) Play Again!
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto
if "%Choice%"=="2" goto first
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
You are using a primitive version of the color print routine that cannot handle characters that are invalid in file names: \, /, :, ", ?, *, &, |, <, >. The version you are using attempts to create a file with a name equal to your displayed string, so it cannot work for your question string.
The top three answers at How to have multiple colors in a Windows batch file? have more sophisticated versions (more complicated), that can handle nearly any character.
The question mark in the text is screwing it up. By the way, I think you mean line 70 is the one that's failing.

Batch File for application restart

I'm new to this so try to keep my question relevant! I'm trying to write a batch file that will re-start an application on a 2 state condition i.e. when a ping fails and then recovers. I've written something gleaned from information given on this site (see below) that just restarts it when it fails and changes the DOS prompt colour, but it's not ideal. Can anyone point me in the general direction to restart the app on a down -> up condition with a ping? Many thanks!
#echo off
cls
set INTERVAL=120
:top
ping -n 1 -w 2000 192.168.1.10 | find "TTL="
IF ERRORLEVEL 1 (SET OUT=4F & echo Request timed out.) ELSE (SET OUT=2F)
IF ERRORLEVEL 1 goto reset
COLOR %OUT%
ping -n 2 -l 100 127.0.0.1 >nul
goto top
:reset
timeout %INTERVAL%
taskkill /IM VmsClientApp.exe /F
Ping -n 1 -l 256 127.0.0.1 >nul
start /D "c:\Program Files\Avigilon\Avigilon Control Center Client\" VmsClientApp.exe
echo The Client is now loading...
goto top
#echo off
setlocal enableextensions disabledelayedexpansion
set "interval=120"
cls
:up
color 2f
set "down="
:test
ping -n 1 -w 2000 192.168.1.10 | find "TTL="
if not errorlevel 1 if defined down goto :restart
if errorlevel 1 set "down=1" & color 4f
timeout %interval%
goto :test
:restart
taskkill /IM VmsClientApp.exe /F
start "" /D "c:\Program Files\Avigilon\Avigilon Control Center Client" VmsClientApp.exe
goto :up

How do I add a timer to a batch file?

I want to make a batch file that waits for a few minutes, then executes a command. How would I do this? Specifically, I want it to end another program in 3 minutes after opening the file.
Use timeout. That will let you wait for a number of seconds given in it's /t parameter. timeout /t 180 will sleep for 3 minutes (180 seconds).
TIMEOUT [/T] timeout [/NOBREAK]
Description:
This utility accepts a timeout parameter to wait for the specified
time period (in seconds) or until any key is pressed. It also
accepts a parameter to ignore the key press.
Parameter List:
/T timeout Specifies the number of seconds to wait.
Valid range is -1 to 99999 seconds.
/NOBREAK Ignore key presses and wait specified time.
/? Displays this help message.
NOTE: A timeout value of -1 means to wait indefinitely for a key press.
Examples:
TIMEOUT /?
TIMEOUT /T 10
TIMEOUT /T 300 /NOBREAK
TIMEOUT /T -1
Another method is to ping an invalid IP address for a certain amount of time:
PING 1.1.1.1 -n 1 -w 60000 >NUL
60000 = milliseconds
hi i love stockoverflow but sometimes the answers are too concise... so heres more than you asked for... the timer and many other snipits
#ECHO off
MODE CON:COLS=25 LINES=11
cls
color 0B
:taskkill
echo.
echo Program To Shutdown
echo.
set /p taskkill=
if "%taskkill%" == "%taskkill%" goto taskkillconfirm
exit
:taskkillconfirm
color 0B
:image
set image=/im
if "%image%" == "%image%" goto imageconfirm
exit
:imageconfirm
color 0B
:forced
set forced=/f
if "%forced%" == "%forced%" goto forcedconfirm
exit
:forcedconfirm
cls
:hour
color 0B
echo.
echo. Hours?
echo.
set /p hour=
:min
color 0B
cls
echo.
echo Minutes?
echo.
set /p min=
:sec
color 0B
cls
echo.
echo Seconds?
echo.
set /p sec=
:continue
color 0B
cls
echo %taskkill%
echo Program Shutdown in
echo %hour% Hours
echo %min% Minutes
echo %sec% Seconds
set /a sec="%sec%-1"
if %sec%==-1 set /a min="%min%-1"
if %sec%==-1 set /a sec="59"
if %min%==-1 set /a hour="%hour%-1"
if %min%==-1 set /a min="59"
if %hour%==-1 goto done
ping -n 2 127.0.0.1 >NUL
goto continue
:done
color 0B
cls
taskkill %image% %taskkill% %forced%
exit
hope you really enjoy this answer
Simple, try this
#echo off
echo Do you want to read word file or pdf file? Hit any key for options...
pause >nul
echo w for word
echo p for pdf
::set input =
set /p input = Choose your option
if %input% == w goto w
if %input% == p goto p
:w
echo Reading Word file...
::start /your/path/to/your/Office/winword.exe
/path/to/your/doc/file/filename.doc
echo Timer starts
pause >nul
echo 10
ping localhost -n 2 >nul
cls
echo 9
ping localhost -n 2 >nul
cls
echo 8
ping localhost -n 2 >nul
cls
echo 7
ping localhost -n 2 >nul
cls
echo 6
ping localhost -n 2 >nul
cls
echo 5
ping localhost -n 2 >nul
cls
echo 4
ping localhost -n 2 >nul
cls
echo 3
ping localhost -n 2 >nul
cls
echo 2
ping localhost -n 2 >nul
cls
echo 1
ping localhost -n 2 >nul
cls
echo Time's up. Starting the next document...
::you can copy/paste the above commands to start another word file
:p
echo Reading Pdf file...
echo Timer starts
::start /your/path/to/your/Acrobat/acrord32.exe
/path/to/your/pdf/file/filename.pdf
pause >nul
echo 10
ping localhost -n 2 >nul
cls
echo 9
ping localhost -n 2 >nul
cls
echo 8
ping localhost -n 2 >nul
cls
echo 7
ping localhost -n 2 >nul
cls
echo 6
ping localhost -n 2 >nul
cls
echo 5
ping localhost -n 2 >nul
cls
echo 4
ping localhost -n 2 >nul
cls
echo 3
ping localhost -n 2 >nul
cls
echo 2
ping localhost -n 2 >nul
cls
echo 1
ping localhost -n 2 >nul
cls
echo Times up. Starting the next document...
::you can copy/paste the above commands to start another Pdf file

Resources