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

Author Topic: Need help for a batch file  (Read 3883 times)

0 Members and 1 Guest are viewing this topic.

xcharge50

    Topic Starter


    Beginner

    Need help for a batch file
    « on: February 01, 2009, 10:12:26 PM »
    Is a little batch to run ip config I make because one of my friend is scare of command prompt! (since I use choice.exe I know is only work in vista or maybe other...). Anyway I think I make some bug an I need a cleanup. Plx can you tell me what to do (or copy paste the code with modification)? Thx a lots! P.S. 1.Sorry for my bad english since is not my native language 2. You are free to add your credit to the code or make it look better =)

    here the code :

    :start
    @echo off
    color 1f
    @echo ----------------------------------------------------------------------
    @echo.
    @echo  ______   ____                                  ___                 
    @echo /\__  _\ /\  _`\                              /'___\ __             
    @echo \/_/\ \/ \ \ \L\ \        ___    ___     ___ /\ \__//\_\     __     
    @echo    \ \ \  \ \ ,__/       /'___\ / __`\ /' _ `\ \ ,__\/\ \  /'_ `\   
    @echo     \_\ \__\ \ \/       /\ \__//\ \L\ \/\ \/\ \ \ \_/\ \ \/\ \L\ \
    @echo     /\_____\\ \_\       \ \____\ \____/\ \_\ \_\ \_\  \ \_\ \____ \
    @echo     \/_____/ \/_/        \/____/\/___/  \/_/\/_/\/_/   \/_/\/___L\ \
    @echo                                                              /\____/
    @echo                                                              \_/__/
    @echo.
    @echo.---------------------------------------------------- Make by: Charge50
    @echo.
    @echo (S)imple (no info) or (P)ro (All info) mode? press (Q) to quit
    @echo.
    @echo Run this file as administrator
    @echo (if you want to use Ip release)
    @echo.
    @echo (S, P or Q)
    choice /n /c qsp
    if errorlevel 3 goto pro
    if errorlevel 2 goto simple
    if errorlevel 1 goto quit
    :simple
    cls
    @echo Do you want to run Ip Release (recomended)
    @echo.
    @echo you need to right click on you icon
    @echo an run as administrator
    @echo to run this function
    @echo.
    @echo (Y or N)
    choice /n /c yn
    if errorlevel 2 goto cren
    if errorlevel 1 goto release
    :release
    cls
    @echo Ip is gona be release in 5 sec
    @echo (If operation take more than 45 sec close the windows)
    ping localhost -n 6 1>NUL 2>&1
    @echo.
    ipconfig /release 1>NUL 2>&1
    if errorlevel 1 goto norel
    @echo.
    @echo.----------
    @echo Ip Release
    @echo.----------
    :cren
    cls
    @echo Do you want to run Ip Renew (The repair)
    @echo.
    @echo (Y or N)
    choice /n /c yn
    if errorlevel 2 goto quit
    if errorlevel 1 goto renew
    :renew
    cls
    @echo Ip is gona be renew in 5 sec
    @echo (If operation take more than 45 sec close the windows)
    @echo.
    ping localhost -n 6 1>NUL 2>&1
    ipconfig /renew 1>NUL 2>&1
    if errorlevel 1 goto norel
    @echo.
    @echo.--------
    @echo Ip Renew
    @echo.--------
    @echo.
    @echo you ip is supposed to be ok
    @echo.
    pause
    :quit
    cls
    @echo press any key to exit
    pause 1>NUL 2>&1
    exit
    :norel
    cls
    @echo ------------------------------
    @echo Ip release fail!
    @echo ------------------------------
    @echo Did you run as administrator?
    @echo The option release is optional
    @echo.
    @echo Do you want to run Ip Renew instead? (the repair)
    @echo or press R to retry Ip release
    @echo.
    @echo (Y, N or R)
    choice /n /c ryn
    if errorlevel 3 goto exit
    if errorlevel 2 goto renew
    if errorlevel 1 goto release
    :noren
    cls
    @echo ------------------------------
    @echo Ip renew fail!
    @echo ------------------------------
    @ For some reason Ip renew fail!
    @echo.
    @echo Do you want to try again? (Y or N)
    @echo or press R to restart the program
    @echo.
    @echo (Y, N or R)
    choice /n /c ryn
    if errorlevel 3 goto quit
    if errorlevel 2 goto renew
    if errorlevel 1 goto start
    :startpro
    @echo ----------------
    @echo Ip Repair Batch
    @echo.----------------
    :pro
    @echo.
    @echo Do you want to run Ip Release
    @echo You may need to run as administrator
    @echo.
    @echo (Y or N)
    @choice /n /c yn
    if errorlevel 2 goto crenpro
    if errorlevel 1 goto releasepro
    :releasepro
    @echo.
    ipconfig /release
    if errorlevel 1 goto norelpro
    pause
    @echo.
    @echo.----------
    @echo Ip Release
    @echo.----------
    :crenpro
    @echo.
    @echo Do you want to run Ip Renew
    @echo.
    @echo (Y or N)
    choice /n /c yn
    if errorlevel 2 goto quitpro
    if errorlevel 1 goto renewpro
    :renewpro
    @echo.
    ipconfig /renew
    if errorlevel 1 goto norelpro
    pause
    @echo.
    @echo.--------
    @echo Ip Renew
    @echo.--------
    @echo.
    @echo you ip is supposed to be ok
    goto quitpro
    :norelpro
    @echo.
    @echo ------------------------------
    @echo Ip release fail!
    @echo ------------------------------
    @echo Did you run as administrator?
    @echo.
    @echo Do you want to run Ip Renew instead?
    @echo or press R to retry Ip release
    @echo.
    @echo (Y, N or R)
    choice /n /c ryn
    if errorlevel 3 goto quitpro
    if errorlevel 2 goto renewpro
    if errorlevel 1 goto releasepro
    :norenpro
    @echo.
    @echo ------------------------------
    @echo Ip renew fail!
    @echo ------------------------------
    @ For some reason Ip renew fail!
    @echo.
    @echo Do you want to try again?
    @echo or press R to restart the program
    @echo.
    @echo (Y, N or R)
    choice /n /c ryn
    if errorlevel 3 goto quitpro
    if errorlevel 2 goto renewpro
    if errorlevel 1 goto start
    :quitpro
    @echo.
    ipconfig /?
    @echo ----------------------
    @echo type exit to quit cmd
    @echo ----------------------
    cmd

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Need help for a batch file
    « Reply #1 on: February 02, 2009, 06:16:45 PM »
    The choice commands are using invalid switch syntax:

    Wrong:
    Code: [Select]
    choice /n /c qsp

    Right:
    Code: [Select]
    choice /n /c:qsp

    This too is right; your choice!
    Code: [Select]
    choice /n /cqsp


    Check all your choice commands. You were very consistent.  ;)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    BatchFileCommand



      Hopeful
    • Thanked: 1
      Re: Need help for a batch file
      « Reply #2 on: February 02, 2009, 06:19:57 PM »
      If you put @echo off at the beginning. You don't need all those  @'s .
      οτη άβγαλτος μεταφ βαθμολογία

      xcharge50

        Topic Starter


        Beginner

        Re: Need help for a batch file
        « Reply #3 on: February 02, 2009, 10:08:15 PM »
        The choice commands are using invalid switch syntax:

        Wrong:
        Code: [Select]
        choice /n /c qsp

        Right:
        Code: [Select]
        choice /n /c:qsp

        This too is right; your choice!
        Code: [Select]
        choice /n /cqsp


        Check all your choice commands. You were very consistent.  ;)


        Thx for the tip so i guess choice /n /c qsp can work with choice.exe but not .com an  /n /c:qsp work with both.

        anyway I'm currently trying to remove some <junk> an repost it after I add windsock repair...but actually I don't know where to put it in the code (after ip renew? after...). Also I guest by copy choice.com in the same folder of the batch will make it work in windows xp an vista (since I think choice.exe don't work in xp...)
        « Last Edit: February 02, 2009, 10:24:21 PM by xcharge50 »

        xcharge50

          Topic Starter


          Beginner

          Re: Need help for a batch file
          « Reply #4 on: February 02, 2009, 10:14:15 PM »
          If you put @echo off at the beginning. You don't need all those  @'s .

          Also thx for the tips! Is my second batch file (First 1 was hello world XD) so is a little <RAW>  ;)

          Sidewinder



            Guru

            Thanked: 139
          • Experience: Familiar
          • OS: Windows 10
          Re: Need help for a batch file
          « Reply #5 on: February 03, 2009, 04:53:37 AM »
          If backward compatibility is not a concern, then use the Vista choice options as /c qsp. Both choice.exe (NT prior to Vista) and choice.com (DOS) will break with a space between the /c switch and the choices.

          Repeating the last suggestion, use @echo off at the top of your file and remove the @ from the other echo statements.

          To prevent writing duplicate code, put the ipconfig /renew and ipconfig /release statements in subroutines where you can call them at the appropriate times.

          Quote
          anyway I'm currently trying to remove some <junk> an repost it after I add windsock repair...but actually I don't know where to put it in the code (after ip renew? after...)

          Repairing the winsock catalog is done with the netsh utility. Not sure you should put it here or design a batch application for netsh separately.

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

          -- Albert Einstein