I'm having trouble with a If statement in.bat

August 26, 2010 at 08:04:47
Specs: Windows 7
Below is my little toy, im having trouble with my if, then shizz, i can't seem to remember how to get it to go back to the options list if some enters say a number thats not listed or a letter on accident, like if else or something?!?!?! im sooo lost please help and feel free to just put your own ideas into this batch file!!

@echo off
title []D[][]V[][]D
ECHO.###########################################################
ECHO.## Network Commands Utility ##
ECHO.## --------------------------------------------- ##
ECHO.## ##
ECHO.## Hi, tried everything else I take it? ##
ECHO.## m3hh ##
ECHO.## each option will run a command then exit ##
ECHO.## ##
ECHO.## close window @anytime ##
ECHO.## ##
ECHO.## or just use opt. 6 ##
ECHO.## ##
ECHO.###########################################################
Echo.
Echo.
Echo. This will attempt to fix connectivity problems
Echo.
Echo.------------------------
Echo.1.Flush yourr DNS?
Echo.2.Delete your arpcache?
Echo.3.Release your IP address?
Echo.4.Renew your IP address?
Echo.5.Netstats!!
Echo.6.Taskkill
Echo.------------------------
set /p userinp=Now choose option 1-6:
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
if "%userinp%"=="5" goto 5
if "%userinp%"=="6" goto 6
GOTO start
if not goto LABEL
:1
GOTO FLUSHDNS
:2
GOTO ARP
:3
GOTO RELEASE
:4
GOTO RENEW
:5
GOTO ANO
:6
GOTO END

:FLUSHDNS
ipconfig/flushdns
GOTO LABEL

:ARP
netsh interface ip delete arpcache
arp -d
GOTO LABEL

:RELEASE
ipconfig/release
GOTO LABEL

:RENEW
ipconfig/renew
GOTO LABEL

:ANO
netstat -ano
pause

:END
Exit


See More: Im having trouble with a If statement in.bat

Report •


#1
August 26, 2010 at 08:07:51
i now realise that that came out a little sloppy once uploaded, the pound signs were a border around some txt so ignore that syntax, just curious about the if else or whatever it would be, i got it to relist the options once you do what ever task you wanted to do so it wouldnt automatically close, and i dont want them to be a series, just want to make it so in the initial process choice, keystroke errors dont close out the .cmd

Report •

#2
August 26, 2010 at 15:01:13
You would write an IF/ELSE like this:

 IF EXIST filename (COMMAND) ELSE (COMMAND)

But it can also be used with comparisons, and can be spead out like this:

IF "%Variable%"=="somethingelse" (
	COMMAND
) ELSE (
	COMMAND
)

I Recommend you enter "IF /?" in the prompt and read what it says.

Report •

Related Solutions


Ask Question