I am trying to create a script that will allow me 10 various scripts to run. I want the menu selection to proceed in the current window instead of opening a new windows. What am I missing? Code: @ECHO OFF pushd %~dp0 SetLocal EnableDelayedExpansion:color and title color 1f title place title here :Set some defaults for later set ERRORTEMP=0 ECHO =============================================================================== ECHO. PLACE HOLDER FOR MENU TITLE ECHO =============================================================================== ECHO. ^(0^) - Select This Option ECHO. ^(1^) - Select This Option ECHO. ^(2^) - Select This Option ECHO. ^(3^) - Select This Option ECHO. ^(4^) - Select This Option ECHO. ^(5^) - Select This Option ECHO. ^(6^) - Select This Option ECHO. ^(7^) - Select This Option ECHO. ^(8^) - Select This Option ECHO. ^(9^) - Select This Option ECHO =============================================================================== choice /c 0123456789q /n /m "Choose a menu option, or q to Quit: " SET ERRORTEMP=!ERRORLEVEL! IF !ERRORTEMP! EQU 0 (GOTO :Selection0) IF !ERRORTEMP! EQU 1 (GOTO :Selection1) IF !ERRORTEMP! EQU 2 (GOTO :Selection2) IF !ERRORTEMP! EQU 3 (GOTO :Selection3) IF !ERRORTEMP! EQU 4 (GOTO :Selection4) IF !ERRORTEMP! EQU 5 (GOTO :Selection5) IF !ERRORTEMP! EQU 6 (GOTO :Selection6) IF !ERRORTEMP! EQU 7 (GOTO :Selection7) IF !ERRORTEMP! EQU 8 (GOTO :Selection8) IF !ERRORTEMP! EQU 9 (GOTO :Selection9) IF !ERRORTEMP! EQU q (GOTO :QUIT) GOTO :MAINMENU :Selection0 batchfile0.cmd GOTO :QUIT :Selection1 batchfile1.cmd :Selection2 batchfile2.cmd :Selection3 batchfile3.cmd :Selection4 batchfile4.cmd :Selection5 batchfile5.cmd :Selection6 batchfile6.cmd :Selection7 batchfile7.cmd :Selection8 batchfile8.cmd :Selection9 batchfile9.cmd :QUIT CLS ECHO =============================================================================== ECHO. QUIT MESSAGE GOES HERE 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
Check that the single CMD files, you want to open, end with 'goto:eof' and use Code: call batchfile1.cmd They will open and same window.
Give Menu an adress first. Then check that the single CMD files, you want to open, end with 'goto:eof' and use Code: @ECHO OFF pushd %~dp0 SetLocal EnableDelayedExpansion:color and title color 1f title place title here :Set some defaults for later :MAINMENU set ERRORTEMP=0 ECHO =============================================================================== ECHO. PLACE HOLDER FOR MENU TITLE ECHO =============================================================================== ECHO. ^(0^) - Select This Option ECHO. ^(1^) - Select This Option ECHO. ^(2^) - Select This Option ECHO. ^(3^) - Select This Option ECHO. ^(4^) - Select This Option ECHO. ^(5^) - Select This Option ECHO. ^(6^) - Select This Option ECHO. ^(7^) - Select This Option ECHO. ^(8^) - Select This Option ECHO. ^(9^) - Select This Option ECHO =============================================================================== choice /c 0123456789q /n /m "Choose a menu option, or q to Quit: " SET ERRORTEMP=!ERRORLEVEL! IF !ERRORTEMP! EQU 0 (GOTO :Selection0) IF !ERRORTEMP! EQU 1 (GOTO :Selection1) IF !ERRORTEMP! EQU 2 (GOTO :Selection2) IF !ERRORTEMP! EQU 3 (GOTO :Selection3) IF !ERRORTEMP! EQU 4 (GOTO :Selection4) IF !ERRORTEMP! EQU 5 (GOTO :Selection5) IF !ERRORTEMP! EQU 6 (GOTO :Selection6) IF !ERRORTEMP! EQU 7 (GOTO :Selection7) IF !ERRORTEMP! EQU 8 (GOTO :Selection8) IF !ERRORTEMP! EQU 9 (GOTO :Selection9) IF !ERRORTEMP! EQU q (GOTO :QUIT) GOTO :MAINMENU :Selection0 call batchfile0.cmd pause GOTO :MAINMENU :Selection1 batchfile1.cmd :Selection2 batchfile2.cmd :Selection3 batchfile3.cmd :Selection4 batchfile4.cmd :Selection5 batchfile5.cmd :Selection6 batchfile6.cmd :Selection7 batchfile7.cmd :Selection8 batchfile8.cmd :Selection9 batchfile9.cmd :QUIT CLS ECHO =============================================================================== ECHO. QUIT MESSAGE GOES HERE 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 They will open and same window.
Atm it assumes the file in same directory like main script. In case it's in a subfolder you need to adapt the path . Code: call "subfolder\script.cmd"
Work in progress. Right now it's an empty file that executes a hello command Here is the content Code: echo you're reached bachfile0 goto:eof
Then it should work, calling an Office Installer script to run inside WU TOOL window that way . Check without ' as it might break it .
Reading definitely helps . There's a little 'design' error in the menu, since it checks for an errorlevel 0 which isn't available here. Also you can reduce the menu to use the errorlevel directly, like this ...: Code: ::=============================================================================================================== ::QUERY WU LOG :QueryLog cls call :MenuHeader " QUERY WU LOG" echo [Q] QUERY SINGLE UPDATE KBs echo [F] QUERY FROM TEXT FILE echo: echo [D] DOWNLOAD THE LINK LIST echo: echo BACK TO MAIN MENU call :MenuFooter echo: CHOICE /C QFDB /N /M "%username%s CHOICE ?:" if %errorlevel%==1 goto :QueryLogManually if %errorlevel%==2 goto :QueryLogTextFile if %errorlevel%==3 goto :DownloadData if %errorlevel%==4 goto:MainMenu goto:QueryLog ::=============================================================================================================== ::MENU HEADER :MenuHeader echo =============================================================================== echo %~1 echo =============================================================================== goto:eof ::=============================================================================================================== :: MENU FOOTER :MenuFooter echo =============================================================================== echo: goto:eof
Changed the code to the following below. Now when I press 0 it foes to the quit option Code: @ECHO OFF pushd %~dp0 SetLocal EnableDelayedExpansion :color and title color 1f title place title here :Set some defaults for later :MAINMENU set ERRORTEMP=0 ECHO =============================================================================== ECHO. PLACE HOLDER FOR MENU TITLE ECHO =============================================================================== ECHO. ^(0^) - Select This Option ECHO. ^(1^) - Select This Option ECHO. ^(2^) - Select This Option ECHO. ^(3^) - Select This Option ECHO. ^(4^) - Select This Option ECHO. ^(5^) - Select This Option ECHO. ^(6^) - Select This Option ECHO. ^(7^) - Select This Option ECHO. ^(8^) - Select This Option ECHO. ^(9^) - Select This Option ECHO =============================================================================== choice /c 0123456789q /n /m "Choose a menu option, or q to Quit: " if %errorlevel%==0 goto :Selection0 if %errorlevel%==1 goto :Selection1 if %errorlevel%==2 goto :Selection2 if %errorlevel%==3 goto :Selection3 if %errorlevel%==4 goto :Selection4 if %errorlevel%==5 goto :Selection5 if %errorlevel%==6 goto :Selection6 if %errorlevel%==7 goto :Selection7 if %errorlevel%==8 goto :Selection8 if %errorlevel%==9 goto:QUIT :Selection0 call file0.cmd GOTO :QUIT :Selection1 call file1.cmd :Selection2 call file2.cmd :Selection3 call file3.cmd :Selection4 call file4.cmd :Selection5 call file5.cmd :Selection6 call file6.cmd :Selection7 call file7.cmd :Selection8 call file8.cmd :Selection9 call file9.cmd :QUIT CLS ECHO =============================================================================== ECHO. QUIT MESSAGE GOES HERE 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
As said: when using choice the first errorlevel is 1 and so on, not 0. Equal what choices i.e. 1,2,3,4,5 or A,B,C,D,E >> errorlevel is always from 1,2,...,5.
Crap, I see where my problem is. If I remove the following code then it executes properly Code: :QUIT CLS ECHO =============================================================================== ECHO. QUIT MESSAGE GOES HERE 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 Here is the code now Code: @ECHO OFF pushd %~dp0 SetLocal EnableDelayedExpansion :color and title color 1f title place title here :Set some defaults for later :MAINMENU set ERRORTEMP=0 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 ABCDEFGHIJ /N /M "Choose a menu option, 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%==8 goto :SelectionH if %errorlevel%==9 goto :SelectionI if %errorlevel%==10 goto :SelectionJ if %errorlevel%==11 goto:QUIT :SelectionA call file0.cmd GOTO :QUIT :SelectionB call file1.cmd :SelectionC call file2.cmd :SelectionD call file3.cmd :SelectionE call file4.cmd :SelectionF call file5.cmd :SelectionG call file6.cmd :SelectionH call file7.cmd :SelectionI call file8.cmd :SelectionJ call file9.cmd The problem now is I really need the removed code to work Code: CLS ECHO =============================================================================== ECHO. QUIT MESSAGE GOES HERE 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
Wow man seriously, this missing factor was Code: ^( . Thanks man Do you have any examples of how to make a footer in the main menu?
FYI 1: Several signs needs to be escaped when one will echo to screen or file: (),<>,|,& need '^', % needs another %. FYI 2: variables only need to be expressed as !var! when you assign a runtime variable inside a for-loop to the var and the use that var inside the same loop. Example: Code: @echo off title ... by s1ave77 :: Code by s1ave77 color 4F setlocal EnableDelayedExpansion ::=============================================================================================================== echo -------------------------------------------------------------------------------- echo RUNTIME VARIABLE USAGE IN FOR /R LOOPs echo -------------------------------------------------------------------------------- echo: set "path=f:\win" set "ext=iso" for /r "%path%" %%f in (*.%ext%) do ( set file=%%~f set filepath=%%~dpf set filenamewo=%%~nf set filename=%%~nxf set extension=%%~xf set size=%%~zf echo Assuming the rt variable is %%%%Y: echo: echo filepath.....^| %%%%~Y ^| !file! echo folderpath...^| %%%%~dpY ^| !filepath! echo filename.ext.^| %%%%~nY ^| !filename! echo filename.....^| %%%%~nxY ^| !filenamewo! echo extension....^| %%%%~zY ^| !extension! echo size.[byte]..^| %%%%~zY ^| !size! ) echo: echo -------------------------------------------------------------------------------- echo: pause endlocal exit Will show: Code: -------------------------------------------------------------------------------- RUNTIME VARIABLE USAGE IN FOR /R LOOPs -------------------------------------------------------------------------------- Assuming the rt variable is %%Y: filepath.....| %%~Y | f:\win\x64.iso folderpath...| %%~dpY | f:\win\ filename.ext.| %%~nY | x64.iso filename.....| %%~nxY | x64 extension....| %%~zY | .iso size.[byte]..| %%~zY | 334073856 -------------------------------------------------------------------------------- Drücken Sie eine beliebige Taste . . .
Thanks i'll have to scratch the footer idea. No time to go back and rewrite this, im on a roll now, lol.