How do I add a timer to a batch file? - 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

Related

Batch file is executing wrong variable

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.

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

Batch script to ping remote computer every 5 seconds?

I'm trying to create a script that pings my remote computer like every 5 or 10 seconds to see if it is back online after rebooting.
I have this code that seems to work but spams like crazy, and I only need it to check every 5 seconds or so.
A bonus to it would be if it stops the loop once it gets a successful connection.
#echo off
:loop
echo Checking connection...
ping -n 1 xx.xxx.xxx.xx >nul
if errorlevel 1 (
cls
echo Computer is offline
goto loop>nul
)
cls
echo Computer is online
goto loop>nul
#echo off
:loop
ping -n 1 -w 500 -4 xx.xx.xx.xx 2>nul|find "TTL=" >nul||(echo offline & ping -w 1000 -n 6 localhost >nul & goto loop)
echo online
Below would be the fine solution for your issue, i guess. try this script and let me know if tat works.
#!/bin/ksh
pingSuccess=0
while [ 1 -eq 1 ]
do
ping -c 1 $1 >/dev/null 2>&1 && pingSuccess=1
[ ${pingSuccess} -eq 1 ] && echo "got the successful ping. " && break
echo "ping failed. sleeping for 5 secs" && sleep 5
done
echo "exitting.."; exit 0
Did not test, but this should work:
#echo off
SET IP=xxx.xxx.xxx.xxx
SET TIMEOUT=5000
:loop
echo Checking connection...
ping -n 1 %IP% >nul
if errorlevel not 0 (
cls
echo Computer at %IP% is offline, waiting %TIMEOUT%ms before retrying
ping -n 1 1.0.0.1 -w %TIMEOUT% >nul
goto loop>nul
)
echo Computer at %IP% is online
you can change
SET IP=xxx.xxx.xxx.xxx
to:
SET IP=%1
and give the IP address as argument to the batch file.
Also, make sure IP 1.0.0.1 is not reachable, it is used to create the timeout.
Here is how I would do it.
#echo off
setlocal
:pingagain
set /a inc+=5
set "ip=xx.xx.xx.xx"
Call :IsPingable %ip% && (
Echo %ip% is online
) || (
Echo %ip% is not online yet.
ping 127.0.0.1 -n 1 -w 5000>nul
goto :pingagain)
exit /b
:IsPingable <comp>
ping -n 1 -w 3000 -4 -l 8 "%~1" | Find "TTL=">nul
exit /b

the set/p command in batch files

I am trying to make a batch script that hides folders, files, ect. But I can only get it to work when the file name has no spaces. I have listed the code I have so far below.
I need some help getting it to work with spaces. Keep in mind I am sort of new to batch scripting, but have a pretty good idea of what I am doing. Also, please explain what your solution is (if you have one).
>#echo off
title File hider
:start
cls
Echo Do You Want to Hide or Unhide a Folder?
echo.
echo.
set/p cho=Choice:
if %cho% equ Hide goto a
if %cho% equ hide goto a
if %cho% equ Unhide goto b
if %cho% equ unhide goto b
if %cho% neq Hide goto c
:c
cls
echo That Is An Invalid Choice
pause
goto start
:a
cls
echo Enter the name of the folder you want to hide:
echo.
echo.
set/p name=Folder Name:
if EXIST %name% goto file
if NOT EXIST %name% goto 99
:file
attrib +h +s +r %name%
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
echo Job Completed
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
exit
:b
cls
echo Enter The Name Of The Folder You Want To See:
echo.
echo.
set/p name=Folder Name:
if EXIST %name% goto bellow
if NOT EXIST %name% goto 98
:bellow
attrib -h -s -r %name%
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
echo Job Completed
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
goto question
:question
cls
echo Do you want to open this folder/file?
echo.
echo.
set/p yn=Answer[y:n]
if %yn% equ y goto 1
if %yn% equ n goto 2
if %yn% equ Y goto 1
if %yn% equ n goto 2
if %yn% neq y goto 3
:1
start %name%
exit
:2
exit
:3
cls
echo Invalid Choice
pause
goto question
exit
:99
cls
echo That file name does not exist
pause
goto a
:98
cls
echo that file name does not exist
pause
goto b
You need double quotes like this:
set/p "name=Folder Name: "
if EXIST "%name%" goto file
if NOT EXIST "%name%" goto 99
:file
attrib +h +s +r "%name%"
and the /i makes the test case insensitive.
if /i "%cho%" equ "Hide" goto a
Wherever you have %var% and var contains spaces, you need to use "%var%". Enclosing the string in quotes means the space is not interpreted as a separator. And if you are using an IF statement, then the quotes must be balanced either side of the comparison operator.
Not entirely sure if this is helpful, but this is what I use in my batch files when I ask if the user would like to run another batch file as well (I have an updater that unzips folders from a server, and another that copies over data files. So I use this at the end of each to ask if the user would like to run the other updater).
It also has a warning for invalid entries.
set /p entry=INSERT INSTRUCTION HERE, Type OPTION(S), then press the enter key:
IF /I NOT %entry%==N IF /I %entry%==Y GOTO M1
IF /I NOT %entry%==Y IF /I %entry%==N GOTO M2
IF /I NOT %entry%==N IF /I NOT %entry%==Y GOTO M3
:M1
echo This is where 'Y' directs to.
pause >nul
GOTO END
:M2
echo This is where 'N' directs to.
pause >nul
GOTO END
::The below option is used to revert back to the BEG and is meant for any invalid entries, thus preventing inccorrect entry. This can also prevent the code from continuing until a valid entry is made.
::For a bit of visual fun, it is made to flash red when an ivalid entry is made. To remove, just delete the lines above the GOTO
:M3
cls
^
echo Please try again...^
color ca
ping 127.0.0.1 -n 2 -w 100 >nul
color 4a
ping 127.0.0.1 -n 2 -w 500 >nul
color ca
ping 127.0.0.1 -n 2 -w 500 >nul
color 4a
ping 127.0.0.1 -n 2 -w 500 >nul
color 0a
GOTO BEG
:END
I've noticed a couple things wrong with the code you programmed, so I've made a better version for you!
Original Code:
#echo off
title File hider
:start
cls
Echo Do You Want to Hide or Unhide a Folder?
echo.
echo.
set/p cho=Choice:
if %cho% equ Hide goto a
if %cho% equ hide goto a
if %cho% equ Unhide goto b
if %cho% equ unhide goto b
if %cho% neq Hide goto c
:c
cls
echo That Is An Invalid Choice
pause
goto start
:a
cls
echo Enter the name of the folder you want to hide:
echo.
echo.
set/p name=Folder Name:
if EXIST %name% goto file
if NOT EXIST %name% goto 99
:file
attrib +h +s +r %name%
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
echo Job Completed
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
exit
:b
cls
echo Enter The Name Of The Folder You Want To See:
echo.
echo.
set/p name=Folder Name:
if EXIST %name% goto bellow
if NOT EXIST %name% goto 98
:bellow
attrib -h -s -r %name%
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
echo Job Completed
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
goto question
:question
cls
echo Do you want to open this folder/file?
echo.
echo.
set/p yn=Answer[y:n]
if %yn% equ y goto 1
if %yn% equ n goto 2
if %yn% equ Y goto 1
if %yn% equ n goto 2
if %yn% neq y goto 3
:1
start %name%
exit
:2
exit
:3
cls
echo Invalid Choice
pause
goto question
exit
:99
cls
echo That file name does not exist
pause
goto a
:98
cls
echo that file name does not exist
pause
goto b
Modified version:
#echo off
title File hider
:start
cls
Echo Do You Want to Hide or Unhide a Folder?
echo.
echo.
set/p cho=Choice:
if %cho% equ Hide goto :a
if %cho% equ hide goto :a
if %cho% equ Unhide goto :b
if %cho% equ unhide goto :b
else goto :c
:c
cls
echo That Is An Invalid Choice
pause
goto start
:a
cls
echo Enter the name of the folder you want to hide:
echo.
echo.
set/p name=Folder Name:
if EXIST %name% goto :file
if NOT EXIST %name% goto :99
:file
attrib +h +s +r %name%
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
echo Job Completed
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
exit
:b
cls
echo Enter The Name Of The Folder You Want To See:
echo[
echo[
set/p name=Folder Name:
if EXIST %name% goto :bellow
if NOT EXIST %name% goto :98
:bellow
attrib -h -s -r %name%
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
echo Job Completed
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
ping localhost -5 > nul
goto :question
:question
cls
echo Do you want to open this folder/file?
echo.
echo.
set/p yn=Answer[y:n]
if %yn% equ y goto 1
if %yn% equ n exit
if %yn% equ Y goto 1
if %yn% equ n exit
else goto :3
:1
start %name%
:3
cls
echo Invalid Choice
pause
goto :question
:99
cls
echo That file name does not exist
pause
goto :a
:98
cls
echo that file name does not exist
pause
goto :b
Hopefully that clears a couple things up for you, if there is any errors with the code (there was a lot of lines in this one XD) let me know below!

I Don't Know What Is Wrong With My Batch File

Help! I am making a batch file that you can make a list of people. Then when someone arrives you can type in their name and it will check if they're on the list. When the batch file checks if the person is on the list it does not work(I am using no capital letters and I am spelling it right) I need to figure out what is wrong with my batch file that is not working.
So the main problem is that when it checks for the person on the list it does not find it. Sorry, im not exactly sure how to phrase this. :)
Here is the code for my program.
#echo off
title Event Starter
echo Event Starter
set /p Eventname=Event Name:
cls
goto :Participants
:Participants
title Name Of Participants
set /p Name1=Name:
cls
set /p Name2=Name:
cls
set /p Name3=Name:
cls
set /p Name4=Name:
cls
set /p Name5=Name:
cls
set /p Name6=Name:
cls
set /p Name7=Name:
cls
set /p Name8=Name:
cls
pause
goto :checker
:checker
title Enter Person's Name
echo Enter Who Arrived To Check The Database
echo.
echo.
echo.
set /p check1=
goto :database
:database
title Checking Database For The Given Person
echo Checking Database For The Given Person
cls
echo 5 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 20 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 35 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 50 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 70 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 85 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 100 %
ping 1.1.1.1 -n 1 -w 5000 > nul
if %check1%==%Name1% goto :valid
if %check1%==%Name2% goto :valid
if %check1%==%Name3% goto :valid
if %check1%==%Name4% goto :valid
if %check1%==%Name5% goto :valid
if %check1%==%Name6% goto :valid
if %check1%==%Name7% goto :valid
if %check1%==%Name8% goto :valid
goto :invalid
:valid
title %check% Is On The List!
echo %check% Is On The List!
ping 1.1.1.1 -n 1 -w 5000 > nul
ping 1.1.1.1 -n 1 -w 5000 > nul
pause
goto :checker
:invalid
title %check% Is Not On The List!
echo %check% is Not On The List!
echo This Is Case-Sensative
ping 1.1.1.1 -n 1 -w 5000 > nul
ping 1.1.1.1 -n 1 -w 5000 > nul
goto :checker
To be honest, there is a lot of unnecessary lines there, so instead of pinpointing the error I have rewritten your script into a much cleaner version, which should hopefully solve the problems you were having as well! :)
#echo off
title Event Starter
setlocal enabledelayedexpansion
echo Event Starter
set /p Eventname=Event Name:
cls
title Name Of Participants
for /l %%a in (1,1,8) do (
set /p Name[%%a]=Name:
cls
)
:checker
title Enter Person's Name
echo Enter Who Arrived To Check The Database
echo.
echo.
echo.
set /p check1=
title Checking Database For The Given Person
echo Checking Database For The Given Person
cls
for %%b in (5,20,35,50,70,85,100) do (
echo %percent%%
ping 1.1.1.1 -n 6 > nul
cls
)
for /l %%a in (1,1,8) do (
if !check1!==!Name[%%a]! goto :valid
)
goto :invalid
:valid
title %check% Is On The List!
echo %check% Is On The List!
ping 1.1.1.1 -n 1 -w 10000 > nul
goto :checker
:invalid
title %check% Is Not On The List!
echo %check% is Not On The List!
echo This Is Case-Sensative
ping 1.1.1.1 -n 1 -w 10000 > nul
goto :checker
--EDIT--
Fixed the code. It should work now.
setlocal enabledelayedexpansion
:a
cls
set/p name=Name:
for /f "delims=" %%i in (File_path) do (
set name2=%%i
if /i !name! equ !name2! goto b
)
cls
echo They're not on the list...
pause
goto a
:b
cls
echo They're on the list...
pause
goto a
The script goes through the file checking if the user-defined name (name) is within it. If it is then it sends it to :b which reports back to you saying that they were on the list. You could modify this into a function by replacing the goto command with exit /b 2 for true (they were on the list) and exit /b 3 for false (they weren't).
The names should each be on a separate line, demonstrated below. Capitalization doesn't matter because of the /i switch on the if command.
Mark Finch
Julie Fernz
Tom Riddle...
I am not familiar with the syntax, but there is a difference between the way you input the initial names (e.g. set /p Name1=Name: ) and how you input the name to check (set /p check1= ). Is that significant?

Resources