Answer» Hi, and thank you for reading that. I wrote a small app to "change ip" on my computer in batch. I have 3 dial-up connections, and each one should give another ip every time I disconnect and connect, but it doesn't happen so recently, so I had to do something. I wrote this app: *It works perfectly on XP! for 100%
http://utilitybase.com/paste/6200
*this slash: / should be: \ but I don't know whats wrong with the site I uploaded it to.
As you can see in lines 37-39,
:files_are_the_same cd "C:/Program Files/program" 0142.bat
If the IP hasn't been changed, it goes to the next dial-up connection named as [0142.bat and 0143.bat].
[0142 and 0143 are has the same content as the app you saw, but it connects just to another connection]
The problem in Vista is that it does only the first "loop" - it doesn't go to the next file [connection...]. For example, even if the IP wasn't changed it stops in 0141 and doesn't go on to 0142 and etc.
Why is that? Why it doesn't read the IF's? How to fix that?
Thank you a lot again!! sorry for my ENGLISH, if it's not so correct. If you didn't understand something please write it, and Ill to to rephrase it.
Very nicely written code. Very readable.
I can't really see a loop. Just a return to :files_are_the_same. There are no variables so repetitively running code will produce the same results each time.
Some interesting code:
Code: [Select]:connect rasdial "0141" "USER" "PASSWORD" rasdial "0141" "USER" "PASSWORD" IF NOT ERRORLEVEL 0 goto files_are_the_same IF ERRORLEVEL 0 goto curl1
Should you not be checking errorlevel 1?
Code: [Select]:files_are_the_same cd "C:/Program Files/program" 0142.bat
This a transfer of CONTROL to the 0142.bat file. Is this what you want? Without a call, control will not be transfered back here.
Thank you for the fast reply!
Yes, sorry , I didn't mean loop, I meant that if something goes wrong it should go over and over through 0141->0142->0143->0141... ... ...
Quote from: Sidewinder on March 10, 2008, 04:38:16 PM Very nicely written code. Very readable.
Thank you very much
Code: [Select]:connect rasdial "0141" "USER" "PASSWORD" rasdial "0141" "USER" "PASSWORD" IF NOT ERRORLEVEL 0 goto files_are_the_same IF ERRORLEVEL 0 goto curl1
Should you not be checking errorlevel 1?
Isn't that the same? ERRORLEVEL 1 and NOT ERRORLEVEL 0 ?
Code: [Select]:files_are_the_same cd "C:/Program Files/program" 0142.bat
This a transfer of control to the 0142.bat file. Is this what you want? Without a call, control will not be transfered back here.
umm... It works on XP. I just want it to open 0142.bat in the same cmd window. just to continue running the commands that are written in 0142.bat in the same cmd window
I can't understand, why is that working on XP for 100% and not working on Vista at all. I mean it is working, but it runs only the first opened file 0141.bat, and it doesn't matter what is the result [I mean whether it has changed the IP or not] it won't go on to 0142.bat.
Why :S ?It's doubtful Microsoft would change batch file behavior for Vista. Try turning echo on; by scrolling back the cmd window you should be ABLE to see how the file runs and what paths it follows on the if statements. The errorlevel values seem to be the only decision making logic points in the file.
Quote:connect rasdial "0141" "USER" "PASSWORD" rasdial "0141" "USER" "PASSWORD" IF NOT ERRORLEVEL 0 goto files_are_the_same IF ERRORLEVEL 0 goto curl1
Should you not be checking errorlevel 1?
Isn't that the same? ERRORLEVEL 1 and NOT ERRORLEVEL 0 ?
If I read this right (no pun), the first if checks for negative errorlevels (not 0 and not greater than zero); the second if checks for zero and positive errorlevels. Negative errorlevels are possible but rare. My guess is you always end up in :curl1. If this is correct, then fine. You may want to check this though.
QuoteIsn't that the same? ERRORLEVEL 1 and NOT ERRORLEVEL 0 ? "IF errorlevel 1" means "if errorlevel is 1 or greater", and "If not errorlevel 0" means "if errorlevel is not equal to 0"
|