Multiple choices menu on batch file?

后端 未结 13 1655
盖世英雄少女心
盖世英雄少女心 2020-11-28 12:56

Hi I want to make a batch file menu, that asks \'Select app you want to install?\' for example

  1. App1
  2. App2
  3. App3
  4. App4
  5. App5
13条回答
  •  难免孤独
    2020-11-28 13:32

    Here's an example of a batch script menu I'm using:

    @echo off
    setlocal
    :begin
    cls
    echo [LOCAL ACCOUNTS REMOTE ADMIN] --------------------------------------
    echo   1 -- List local accounts on a remote machine
    echo   2 -- Create a local account on a remote machine
    echo   3 -- Change a local account password on a remote machine
    echo   4 -- Delete a local account on a remote machine
    echo;
    echo   5 -- exit
    echo;
    set /P rmFunc="Enter a choice: "
    echo --------------------------------------------------------------------
    for %%I in (1 2 3 4 5 x) do if #%rmFunc%==#%%I goto run%%I
    goto begin
    
    :run1
    rem list local accounts code
    goto begin
    
    :run2
    rem create local account code
    goto begin
    
    rem and so on, until...
    
    :run5
    :run9
    :run99
    :runx
    endlocal
    goto :EOF
    

    The most relevant bits are the set /p line and the for...in lines. The for...in line basically compares the choice entered with every menu item number, and if match, goto run#; otherwise start over from the beginning.

提交回复
热议问题