Create a batch file with multiple options

后端 未结 5 1532
情深已故
情深已故 2020-12-08 10:13

Hi I want to create a batch which performs more than one operations. Like it should display

1.Restart
2.Shutdown
3.Close all Windows
4.Log off
5         


        
5条回答
  •  甜味超标
    2020-12-08 11:19

    Now someone just put is this your homework... I almost don't want to paste this! lol

    but... I will anyway :p

    echo off
    :begin
    echo Select a task:
    echo =============
    echo -
    echo 1) Option 1
    echo 2) Option 2
    echo 3) Option 3
    echo 4) Option 4
    echo -
    set /p op=Type option:
    if "%op%"=="1" goto op1
    if "%op%"=="2" goto op2
    if "%op%"=="3" goto op3
    if "%op%"=="4" goto op4
    
    echo Please Pick an option:
    goto begin
    
    
    :op1
    echo you picked option 1
    goto begin
    
    :op2
    echo you picked option 2
    goto begin
    
    :op3
    echo you picked option 3
    goto begin
    
    :op4
    echo you picked option 4
    goto begin
    
    :exit
    @exit
    

    You can swap goto begin to goto exit in each of the sections if you want it to run the command then close the batch file, which is what I would recommend, seeing as you want to shutdown.

    Hope this helps.

    Martyn

提交回复
热议问题