Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch in Vista\ REALLY NEED YOUR HELP  (Read 3637 times)

0 Members and 1 Guest are viewing this topic.

rbchtt

    Topic Starter


    Newbie

    Batch in Vista\ REALLY NEED YOUR HELP
    « on: March 10, 2008, 02:04:23 PM »
    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.


    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Batch in Vista\ REALLY NEED YOUR HELP
    « Reply #1 on: March 10, 2008, 04:38:16 PM »
    Very nicely written code. Very readable. :D

    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.

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    rbchtt

      Topic Starter


      Newbie

      Re: Batch in Vista\ REALLY NEED YOUR HELP
      « Reply #2 on: March 10, 2008, 05:06:00 PM »
      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... ... ...

      Very nicely written code. Very readable. :D

      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 ?

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Batch in Vista\ REALLY NEED YOUR HELP
      « Reply #3 on: March 11, 2008, 05:46:33 AM »
      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.

       8)

      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      Dias de verano

      • Guest
      Re: Batch in Vista\ REALLY NEED YOUR HELP
      « Reply #4 on: March 15, 2008, 04:36:45 AM »
      Quote
      Isn'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"