Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

batch file parameter choosing

  • 24-04-2007 08:16PM
    #1
    Registered Users, Registered Users 2 Posts: 1,766 ✭✭✭


    Hi Folks,
    Anyone still have the knack of DOS batch scripting? I would like to create a .bat file which would allow me to choose 1 or 2 for say starting or stopping services. I'd like to find some specific examples or someone would know offhand? It's been awhile! I believe I need to use % for parameters.

    eg.

    REM ** do this **
    %1 run this
    REM ** do that **
    %2 run that


Comments

  • Registered Users, Registered Users 2 Posts: 1,766 ✭✭✭hamster


    Think I found an example I can work with:

    @ECHO OFF
    ECHO 1 - Stars
    ECHO 2 - Dollar Signs
    ECHO 3 - Crosses


    CHOICE /C:123

    IF errorlevel 3 goto CRS
    IF errorlevel 2 goto DLR
    IF errorlevel 1 goto STR

    :STR
    ECHO *******************
    ECHO.
    PAUSE
    CLS
    EXIT

    :DLR
    ECHO $$$$$$$$$$$$$$$$$$$$
    ECHO.
    PAUSE
    CLS
    EXIT

    :CRS
    ECHO +++++++++++++++++++++
    ECHO.
    PAUSE
    CLS
    EXIT


  • Registered Users, Registered Users 2 Posts: 1,766 ✭✭✭hamster


    Found a nice scripting site:

    http://www.robvanderwoude.com/index.html


  • Closed Accounts Posts: 1,974 ✭✭✭mick.fr


    hamster wrote:
    Hi Folks,
    Anyone still have the knack of DOS batch scripting? I would like to create a .bat file which would allow me to choose 1 or 2 for say starting or stopping services. I'd like to find some specific examples or someone would know offhand? It's been awhile! I believe I need to use % for parameters.

    eg.

    REM ** do this **
    %1 run this
    REM ** do that **
    %2 run that

    net start dns
    ...
    net stop dns

    Easiest way rather than creating a menu, or if you insist :

    :: Script start
    :: Kick ass batch file from Mick.fr, the batch killer.
    SET Choice=
    SET /P Choice=Hey budy, please make your choice
    echo.
    echo Press 1 to start the DNS service
    echo Press 2 to stop the DNS service
    echo Press 3 to to get a new boss
    echo Press 4 to get a night out with the gorgeous HR manager
    IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
    echo.
    :: /I makes the IF comparison case-insensitive
    IF /I '%Choice%'=='1' GOTO option1
    IF /I '%Choice%'=='2' GOTO option2
    IF /I '%Choice%'=='3' GOTO option3
    IF /I '%Choice%'=='4' GOTO option4

    :option1
    net start dns

    :option2
    net stop dns

    :option3
    getanewboss.exe
    echo That might work if you publish his CV on Monster.ie

    :option4
    getlaidtonit.exe
    echo That might work if you get a nice bimmer


    But I would rather go with some WSH/VB scripting, or KIXTART which is an excellent and really handy scripting engine, plus it is really easy and powerful.


  • Closed Accounts Posts: 1,974 ✭✭✭mick.fr


    hamster wrote:
    Think I found an example I can work with:
    CHOICE /C:123

    CHOICE is a small app you can get from Windows resource kit, but out of the box it is not on XP+
    Plus this is legacy, SET needs to be used on instead.


  • Registered Users, Registered Users 2 Posts: 1,766 ✭✭✭hamster


    Nice one mick.fr - Choice errored out for me since I didnt have the resource kit (have XP). I found a ref to set /p. Nice example btw - Thanks!


  • Advertisement
  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 96,283 Mod ✭✭✭✭Capt'n Midnight


    mick.fr wrote:
    CHOICE is a small app you can get from Windows resource kit, but out of the box it is not on XP+
    Plus this is legacy, SET needs to be used on instead.
    you can use the choice from dos 6 /window 95 / 98 too.
    use with errorlevel , and you don't have to press enter either

    to see if the DNS service has started
    net start | find /i "DNS"
    if errorlevel 1 echo "dns NOT started"

    a bit of imagination and you get a batch file that will toggle the DNS service.

    might as well add a
    ipconfig /flushdns
    too


Advertisement