Create a batch file with multiple options

后端 未结 5 1535
情深已故
情深已故 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

    This should get you started. The CHOICE command is available in most versions of Windows but may require that you get the Windows NT 4 resource kit. The CHOICE command is available in Windows 7.

    @ECHO OFF
    CLS
    ECHO 1.Restart
    ECHO 2.Shutdown
    ECHO 3.Close all Windows
    ECHO 4.Log off
    ECHO 5.Switch User
    ECHO.
    
    CHOICE /C 12345 /M "Enter your choice:"
    
    :: Note - list ERRORLEVELS in decreasing order
    IF ERRORLEVEL 5 GOTO SwitchUser
    IF ERRORLEVEL 4 GOTO Logoff
    IF ERRORLEVEL 3 GOTO CloseAllWindows
    IF ERRORLEVEL 2 GOTO Shutdown
    IF ERRORLEVEL 1 GOTO Restart
    
    :Restart
    ECHO Restart (put your restart code here)
    GOTO End
    
    :Shutdown
    ECHO Shutdown (put your shutdown code here)
    GOTO End
    
    :CloseAllWindows
    ECHO Close All Windows (put your close all windows code here)
    GOTO End
    
    :Logoff
    ECHO Logoff (put your log off code here)
    GOTO End
    
    :SwitchUser
    ECHO Switch User (put your switch user code here)
    GOTO End
    
    :End
    

提交回复
热议问题