Help with menu script

Discussion in 'Scripting' started by hypedave, Dec 12, 2014.

  1. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #21 Compo, Dec 12, 2014
    Last edited by a moderator: Apr 20, 2017
    Try using this as your base file:
    Code:
    @Echo( Code Removed
     
  2. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #22 hypedave, Dec 12, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Cool thanks, i'll stick with what I have now. Just really need to get a footer in place with out to rewrite the entire thing.

     
  3. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    You don't need to re-write anything, just use copy and paste.

    all this menu script requires are, (in this case), 11 files, most of which you already have:
    1. batchfile1
    2. batchfile2
    3. batchfile3
    4. batchfile4
    5. batchfile5
    6. batchfile6
    7. batchfile7
    8. batchfile8
    9. batchfile9
    10. batchfile10
    11. WPEUtil.exe
     
  4. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #24 hypedave, Dec 13, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Ok would it look something like this?

    Code:
    @Echo Off & SetLocal
    Title place title here
    Color 1f
    If "%CD%\" NEq "%~dp0" PushD %~dp0
    Set RunCount=0
    :MENU
    Echo(    =======================================================================
    Echo(                        PLACE HOLDER FOR MENU TITLE
    Echo(    =======================================================================
    Echo(        [A] - Select This Option
    Echo(         - Select This Option
    Echo(        [C] - Select This Option
    Echo(        [D] - Select This Option
    Echo(        [E] - Select This Option
    Echo(        [F] - Select This Option
    Echo(        [G] - Select This Option
    Echo(        [H] - Select This Option
    Echo(         - Select This Option
    Echo(        [J] - Select This Option
    Echo(    =======================================================================
    Choice /C ABCDEFGHIJQ /N /M " Choose a menu option [A-J], or [Q] to Quit: "
    Set ReturnCode=%ErrorLevel%
    If %ReturnCode% Gtr 10 (If %RunCount% Equ 0 (GoTo :EOF) Else (GoTo :QUIT))
    Set/A RunCount+=1
    Call batchfile1%ReturnCode%
    Call batchfile2%ReturnCode%
    Call batchfile3%ReturnCode%
    Call batchfile4%ReturnCode%
    GoTo :MENU
    :QUIT
    Cls
    Echo(    =======================================================================
    Echo(                           QUIT MESSAGE GOES HERE
    Echo(    -----------------------------------------------------------------------
    Echo(                 Press [R] to Restart PC or  to Shutdown
    Echo(    =======================================================================
    Choice /C RS /T 10 /D R /N /M " System will Auto Reboot in 10 seconds: "
    IF ErrorLevel 2 (WPEUtil Shutdown & Exit/B)
    WPEUtil Reboot
    
    


    And how do I get the footer in. Slave mentioned one way but is there another way to with out totally rewritting
     
  5. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    In case you offer only one menu there's no real need for headers/footers :g:. I use them to avoid redundant code by using one 'header/footer-call-module' for each.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    No I was just really hoping for a footer message for information purposes that's all.
     
  7. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #27 s1ave77, Dec 13, 2014
    Last edited by a moderator: Apr 20, 2017
    No problem. When using call commands you can send parameters with the call, it only needs to prepare the called 'module in the script to use them.

    Syntax would be (to get a clue):

    The call command (parameters are separated by commas)
    Code:
    set "count=0"
    for /r "%cd%" %%a in (*.*) do set /a count+=1
    call :InfoFooter "Processed all files.", "Files count: %count%"
    The count loop i only used to give a clue :cool2:.

    The called Module (placeholders would be %~1 and %~2 here)
    Code:
    ::===============================================================================================================
    ::INFO FOOTER
    :InfoFooter
    echo --------------------------------------------------------------------------------
    echo %~1
    echo %~2
    echo --------------------------------------------------------------------------------
    goto:eof
    
    The module must end with goto:eof.

    Will show as:
    Code:
    --------------------------------------------------------------------------------
    Processed all files.
    Files count: XXX
    --------------------------------------------------------------------------------
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #28 Compo, Dec 14, 2014
    Last edited by a moderator: Apr 20, 2017
    I don't understand why you've changed my code to do something different!
    My intention was that if you selected:
    • A then batchfile1.(cmd|bat) would have been called before returning to the menu selection process.
    • B then batchfile2.(cmd|bat) would have been called before returning to the menu selection process.
    • C then batchfile3.(cmd|bat) would have been called before returning to the menu selection process.
    • D then batchfile4.(cmd|bat) would have been called before returning to the menu selection process.
    • E then batchfile5.(cmd|bat) would have been called before returning to the menu selection process.
    • F then batchfile6.(cmd|bat) would have been called before returning to the menu selection process.
    • G then batchfile7.(cmd|bat) would have been called before returning to the menu selection process.
    • H then batchfile8.(cmd|bat) would have been called before returning to the menu selection process.
    • I then batchfile9.(cmd|bat) would have been called before returning to the menu selection process.
    • J then batchfile10.(cmd|bat) would have been called before returning to the menu selection process.
    • Q then the menu selection process would end.
    If A-J had not been selected then the script would exit
    If A-J had been selected then the shutdown/reboot procedure would be run.

    Now you have it so that if the end user selects, for instance, D then all of the following would happen:
    • batchfile14 would be called.
    • batchfile24 would be called.
    • batchfile34 would be called.
    • batchfile44 would be called before returning to the menu selection process.

    [EDIT]
    Code:
    @Echo( Code Removed
    [/EDIT]
     
  9. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #29 hypedave, Dec 14, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Learning in progress for me. My knowledge with creating batch files is not on the same level as yours and others. Not sure what all i changed to make you upset. Thank you for the help.

     
  10. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    First of all I did not say I was upset, I stated that I didn't understand why you'd changed my code, (especially as I'd told you to just copy and paste it).
    The code you'd changed, was highlighted within a quote section within my response, (unlike your posts, I tend to only quote that which is pertinent to my response).
     
  11. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #31 hypedave, Dec 15, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Ok got everything going now. However im seeing something very strange now. When I boot into the WinPE. Startnet.cmd just opens up multiple command prompt windows. Something is borked with my menu script. If I execute it manually from a PC then no problems. But when I execute inside WinPE it loops. Here is my jacked up code.

    Code:
    @ECHO OFF
    pushd %~dp0
    SetLocal EnableDelayedExpansion
    :color and title
    color 1f
    title TITLE - 12/12/2014
    :Set some defaults for later
    :MAINMENU
    CLS
    IF NOT "!CD!"=="%~dp0" cd /D "%~dp0"
    ECHO ===============================================================================
    ECHO.                      *** TITLE ***                   
    ECHO ===============================================================================
    ECHO.
    ECHO.        [A] - Command Prompt
    ECHO.         - Powershell
    ECHO.
    ECHO.        [C] - OPTION1
    ECHO.
    ECHO.        [D] - OPTION3
    ECHO.        [E] - OPTION4
    ECHO.        [F] - OPTION5
    ECHO.
    ECHO.        [G] - OPTION6
    ECHO.
    ECHO ===============================================================================
    ECHO.                   *** TITLE ***                   
    ECHO ===============================================================================
    CHOICE /C ABCDEFGHIJq /N /M "Choose a menu option [A-F], or [Q] to Quit: "
    if %errorlevel%==1 goto :SelectionA
    if %errorlevel%==2 goto :SelectionB
    if %errorlevel%==3 goto :SelectionC
    if %errorlevel%==4 goto :SelectionD
    if %errorlevel%==5 goto :SelectionE
    if %errorlevel%==6 goto :SelectionF
    if %errorlevel%==7 goto :SelectionG
    if %errorlevel%==11 goto:QUIT
    :SelectionA
    CLS
    START CMD
    GOTO :MAINMENU
    :SelectionB
    CLS
    START POWERSHELL
    GOTO :MAINMENU
    :SelectionC
    CLS
    ECHO ===============================================================================
    ECHO              *** CHANGE ME LATER ***
    ECHO ===============================================================================
    ping -n 10 192.168.34.67
    if errorlevel 1 (
      cls
    ECHO ===============================================================================
    ECHO                    *** Failed, press any key to continue ***
    ECHO ===============================================================================
      pause>nul
      exit
    )
    ECHO.
    ECHO ===============================================================================
    ECHO                    *** Success, press any key to continue ***   
    ECHO ===============================================================================  
    pause>nul
    CLS
    GOTO :MAINMENU
    :SelectionD
    CLS
    CALL main_selectionD.cmd
    GOTO :MAINMENU
    :SelectionE
    CLS
    CALL main_selectionE.cmd
    GOTO :MAINMENU
    :SelectionF
    CLS
    CALL Main_Selection_F.cmd
    GOTO :MAINMENU
    :SelectionG
    CLS
    CALL Main_Selection_G.cmd
    GOTO :MAINMENU
    :QUIT
    CLS
    ECHO ===============================================================================
    ECHO.                    *** LEAVING ***                    
    ECHO -------------------------------------------------------------------------------
    ECHO.                 Press ^(R^) to Restart PC or ^(S^) to shutdown
    ECHO ===============================================================================
    choice /c rs /t 10 /d r /n /m "System will reboot after 10 seconds ^(R/S^): "
    IF !ERRORLEVEL! EQU 1 WPEUTIL reboot
    WPEUTIL shutdown
    
    
    
     
  12. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #32 Compo, Dec 15, 2014
    Last edited by a moderator: Apr 20, 2017

    Well you haven't really got it! have you?
    You have completely ignored the majority of the help others have attempted to give you and produced something which has no bearing to that which you opened this Topic.

    As of now I cannot be bothered to fix your entire script, but lets start by changing the first 37 lines, (quoted above), to this:
    Code:
    @Echo( Code Removed
     
  13. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    Well thanks, it error'd out saying CHOICE was not an available command then exited out of the WinPe session. FYI I also tried your previous posted suggestion and it also gave the same exact error *shrugs*.
     
  14. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #34 s1ave77, Dec 15, 2014
    Last edited by a moderator: Apr 20, 2017
    You need to add choice.exe and choice.exe.mui (from laguage folder in system32) to WinPE. Did this with my Win8.1SE with files from my Win 8.1. Wrks flawlessly :good3:.

    else you can use set /p command, which doesn't need choice.exe.

    Code:
    :MAINMENU
    CLS
    IF NOT "%CD%\"=="%~dp0" CD /D %~dp0
    ECHO ===============================================================================
    ECHO.                      *** TITLE ***                   
    ECHO ===============================================================================
    ECHO.
    ECHO.        [A] - Command Prompt
    ECHO.         - Powershell
    ECHO.
    ECHO.        [C] - OPTION1
    ECHO.
    ECHO.        [D] - OPTION3
    ECHO.        [E] - OPTION4
    ECHO.        [F] - OPTION5
    ECHO.
    ECHO.        [G] - OPTION6
    ECHO.
    ECHO ===============================================================================
    ECHO.                   *** TITLE ***                   
    ECHO ===============================================================================
    set /p userchoice=Choose a menu option [A-F], or [Q] to Quit:
    if "%userchoice%"=="A" goto :SelectionA
    if "%userchoice%"=="B" goto :SelectionB
    if "%userchoice%"=="C" goto :SelectionC
    if "%userchoice%"=="D" goto :SelectionD
    if "%userchoice%"=="E" goto :SelectionE
    if "%userchoice%"=="F" goto :SelectionF
    if "%userchoice%"=="G" goto :QUIT
    goto :MAINMENU
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. hypedave

    hypedave MDL Member

    Oct 14, 2014
    129
    30
    10
    #35 hypedave, Dec 15, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Okay that makes perfect sense now that you mention it. I was in a hurry and used powershell to manually create a new winpe wim for me. Did not realize that forgetting to add certain packages would make things go nuts. I added those two files back and it's smooth sailing now. Thanks!!