Go Back   Computer Forums > General Computing > Software and Operating Systems
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 08-30-2012, 09:02 PM   #11
Beta Member
 
Join Date: Aug 2012
Location: U.S.A.
Posts: 2
Default Re: What is wrong with this Batch (.bat) file?

I wasn't aware there was "0" values in an IP address. I thought they went from 1 to 255.
If not I learned something new.
__________________

wk2311 is offline   Reply With Quote
Old 08-30-2012, 09:09 PM   #12
Daemon Poster
 
Join Date: Jun 2005
Location: US
Posts: 676
Default Re: What is wrong with this Batch (.bat) file?

I meant the errorlevel not ip address.



If you put in an errorlevel they are listed 0 and up.
0 usually isn't listed because it will just default. But if you only use one errorlevel or one given answer then it will default to 0

If you wanted errorlevel1,2,3 or what ever, then you would need to specify what the error would be. Being that we are not using a specific answers (Different ip addresses) dos, ms-dos and command prompt will automatically override your errorlevel and use errorlevel 0. So here we specify what the errorlevel 0 is going to do. In our case, it's the goto command.
__________________

__________________
"The Crazy American says.."
A well regulated Militia, being necessary to the security of a free State,
the right of the people to keep and bear Arms, shall not be infringed.
BuzzStPoint is offline   Reply With Quote
Old 08-30-2012, 09:13 PM   #13
Beta Member
 
Join Date: Aug 2012
Location: U.S.A.
Posts: 2
Default Re: What is wrong with this Batch (.bat) file?

http://www.192.168.0.1 – Notes, Admin, Password | PC Security Look here to find your answer, why it didn't work for that particular IP address.

---------- Post added at 09:13 PM ---------- Previous post was at 09:12 PM ----------

What OS are you running?
wk2311 is offline   Reply With Quote
Old 08-30-2012, 09:23 PM   #14
Daemon Poster
 
Join Date: Jun 2005
Location: US
Posts: 676
Default Re: What is wrong with this Batch (.bat) file?

I'm not sure we are talking about the same thing here.

errorlevel in a batch file doesn't really care if you put in an ip address or not. If the command you are running in the batch doesn't complete correctly it will try to continue, in this case, it will continue to errorlevel 0. In the case of the OP he/she was using errorlevel 2 which would make them specify a specific answer. Since this couldn't be achieved the batch defaulted to errorlevel0 resulting in a loop.

BTW, I run XP and Windows 7
__________________
"The Crazy American says.."
A well regulated Militia, being necessary to the security of a free State,
the right of the people to keep and bear Arms, shall not be infringed.
BuzzStPoint is offline   Reply With Quote
Old 09-02-2012, 07:13 PM   #15
In Runtime
 
WYSIWUG's Avatar
 
Join Date: Aug 2012
Location: New Zelaland
Posts: 381
Default Re: What is wrong with this Batch (.bat) file?

Does error level mean a return code?

I.E
@echo off
:start
cls
color f4
choice /c "1-Exit 2-Shutdown"
if errorlevel 2==goto shutdown
if errorlevel 1==goto exit
:shutdown
shutdown -s -f -t 10 -c Shutting down in ten secs
:exit
exit
:end
WYSIWUG is offline   Reply With Quote
Old 09-02-2012, 08:20 PM   #16
Daemon Poster
 
Join Date: Jun 2005
Location: US
Posts: 676
Default Re: What is wrong with this Batch (.bat) file?

Your new code is close. But may work.

In windows 7. I'm not sure when version of Choice you are using.
but in windows 7 your code would be

choice /C:12 /N /M "1-Exit 2-Shutdown"
if errorlevel 2==goto shutdown
if errorlevel 1==goto exit

Your Shutdown command is broke as well.


But yes, thats the right idea there. Now you can add as many as you like.
For example. you could add a new goto area called reboot and just adjust your shutdown command to reboot the pc instead of shutdown. So then you could have 3 errorlevels.
__________________
"The Crazy American says.."
A well regulated Militia, being necessary to the security of a free State,
the right of the people to keep and bear Arms, shall not be infringed.
BuzzStPoint is offline   Reply With Quote
Old 09-02-2012, 10:45 PM   #17
In Runtime
 
WYSIWUG's Avatar
 
Join Date: Aug 2012
Location: New Zelaland
Posts: 381
Default Re: What is wrong with this Batch (.bat) file?

This one pings ok, but when it go to the errorlevels it just exits, whats up with this .bat?

CODE:

@echo off
:start
cls
color f4
set /p name=Enter Name
echo ****************************
echo Welcome %name%
echo ****************************
pause
cls
echo Enter IP Address Or Domain Name
pause
cls
set /p ip=Enter IP Address
ping %ip%
echo COMPLETE!!!
pause
cls
choice /c:12 "1-Start Over 2-Exit"
if errorlevel 2==goto stop
if errorlevel 1==goto begin
:stop
exit
:begin
goto start
:end
WYSIWUG is offline   Reply With Quote
Old 09-02-2012, 11:02 PM   #18
Daemon Poster
 
Join Date: Jun 2005
Location: US
Posts: 676
Default Re: What is wrong with this Batch (.bat) file?

Oh So close!!

You need the /M switch in your Choice command before your text display.

Quote:
@echo off
:start
cls
color f4
set /p name=Enter Name
echo ****************************
echo Welcome %name%
echo ****************************
pause
cls
echo Enter IP Address Or Domain Name
pause
cls
set /p ip=Enter IP Address
ping %ip%
echo COMPLETE!!!
pause
cls
choice /c:12 /M "1-Start Over 2-Exit"
if errorlevel 2==goto stop
if errorlevel 1==goto begin
:stop
exit
:begin
goto start
:end
Just to clean up the code a bit. In your errorlevel1. Change the goto to start.
Then you can remove the :begin and goto command.
__________________
"The Crazy American says.."
A well regulated Militia, being necessary to the security of a free State,
the right of the people to keep and bear Arms, shall not be infringed.
BuzzStPoint is offline   Reply With Quote
Old 09-02-2012, 11:54 PM   #19
In Runtime
 
WYSIWUG's Avatar
 
Join Date: Aug 2012
Location: New Zelaland
Posts: 381
Default Re: What is wrong with this Batch (.bat) file?

Thanks for helping me guys I whould be lost without you's.
WYSIWUG is offline   Reply With Quote
Old 09-03-2012, 08:45 AM   #20
Daemon Poster
 
Join Date: Jun 2005
Location: US
Posts: 676
Default Re: What is wrong with this Batch (.bat) file?

No problems.
when my stepfather gave me his computer when i was younger (Amstrad PC 8088)

There wasn't anything much you could do.
So a lot of times I just played around with autoexec and batch files.
__________________

__________________
"The Crazy American says.."
A well regulated Militia, being necessary to the security of a free State,
the right of the people to keep and bear Arms, shall not be infringed.
BuzzStPoint is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 05:43 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0