AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
Moderator: DosItHelp
Re: AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
This is great! Thanks for making my ask work!
Brings back a lot of memories from the old Tandy 1000 pre-windows batch menu that I used. If I remember correctly that menu had a windows (boxy) look using the ascii borders.
Like these https://en.wikipedia.org/wiki/Box-drawing_characters
Brings back a lot of memories from the old Tandy 1000 pre-windows batch menu that I used. If I remember correctly that menu had a windows (boxy) look using the ascii borders.
Like these https://en.wikipedia.org/wiki/Box-drawing_characters
Re: AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
In original version 1.4 change these lines (first and last are the same - just to be sure) (lines starting at line 131):
This code uses CHOICE.EXE instead of SET /P. Press 'Y' to continue or 'Q' to quit (return to previous menu).
Saso
Code: Select all
set "choice=!choices:~%errorlevel%,1!"
if not "%choice%"=="0" if not "%choice%"=="%LetterToExitMainMenu%" choice.exe /N /C YQ /M "Press Y to continue or Q to Quit: "
if not "%errorlevel%"=="1" exit /B
if not "%level%"=="0" if "%choice%"=="0" exit /B
if "%level%"=="0" if "%choice%"=="%LetterToExitMainMenu%" exit /B
set "option=!option[%choice%]!"
Saso
Re: AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
Hello, trying to launch 1.5 but bat closed directly, no error, nothing displayed...
Downloaded .zip, extracted all files/folder, opened AutoMenu.bat with notepad++, Select all and paste v1.5 version, CTRL + S and double clik on .bat file as Administrator...
Thanks
Downloaded .zip, extracted all files/folder, opened AutoMenu.bat with notepad++, Select all and paste v1.5 version, CTRL + S and double clik on .bat file as Administrator...
Thanks
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
You're supposed to pass the name of the folder that contains the menu layout as the argument. The example that you get when you run the script by itself (from the command prompt; never run scripts by double-clicking them) is AutoMenu.bat "Windows-DOS Commands Help"
Re: AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
oh ok thanks, so ive try your cmd:
W I N D O W S - D O S C O M M A N D S H E L P
La variable d’environnement option[ n’est pas définie.
Select the desired option (X to exit):
Re: AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
Did you see this note from Aacini:
Or you could test with this:
put automenu.bat into an empty folder, create and run this batch file (it will create a test menu):
and now execute the automenu.bat with "MENU TEST" as a parameter.
What happens?
Saso
Download original version (1.2) and try with that.A small drawback in the scheme used is that the maximum lenght of nested names (260 characters) may be reached if you use very long names with several levels deep. If the "Windows-DOS Commands Help" menu system don't show full names or don't works correctly, try to move it to an upper level folder.
Or you could test with this:
put automenu.bat into an empty folder, create and run this batch file (it will create a test menu):
Code: Select all
@echo off
mkdir "MENU TEST"
break "MENU TEST\1-option1-some text">"MENU TEST\1-option1-some text.cmd"
break "MENU TEST\2-option2-some text">"MENU TEST\2-option2-some text.cmd"
break "MENU TEST\3-option3-some text">"MENU TEST\3-option3-some text.cmd"
break "MENU TEST\4-option4-some text">"MENU TEST\4-option4-some text.cmd"
What happens?
Saso
Re: AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
no sorry, english is not my main langage so translate all is complicated
sorry...
thanks, all good.

thanks, all good.
Re: AutoMenu.bat: simple multi-level menu system (with a coherent help on Windows-DOS commands)
Announcment: new version 2.0 is here.
What's new that justifies major version number change? AutoMenu.bat now supports display of menu options based on user groups!
Antonio designed AutoMenu.bat to have these information in the filename/directory name (delimited by a minus sign '-'):
key to press-short description-long description
I changed this to:
key to press-privilege (group)-short description-long description (long description can have a minus sign in it - it will be displayed)
My design at the moment has 10 groups (0-9).
Menu options for group 0 are visible to everyone, group 9 is for administrators.
Each user can be a member of only *one* group.
AutoMenu.bat checks for privileges in folder (directory) names and in filenames. Privilege 9 is added by default so Admins can see everything.
Usernames with dedicated privileges (groups) are at the end of the AutoMenu.bat - there's no need to have user's with privilege 0 listed. Users probably don't have write access to AutoMenu.bat so I guess it is sufficient to have this list in the .bat itself.
If you add a username to the parameter list (as %2) you can simulate the usage of the menu system for that specific user.
Folder/file privileges can have multiple values. For example if a specific option should be displayed for groups 1 and 2 then privilege 12 is in the file/folder name:
Here is a .bat you can use to create a demo folder with different group access levels:
Now you can run it:
and you will see menu options for general user (group 0 (privilege 0)) if this username of course is not listed in the UUUUU section of the AutoMenu.bat.
or you can simulate user 'username1' (with group access 1):
I added three users: username1, username2, username9 (number is the group number).
And AutoMenu.bat V2.0:
By default it uses CHOICE.EXE (see code to change and to translate other text).
Update 12-aug-2025. added additional code to display username in submenus.
Saso
What's new that justifies major version number change? AutoMenu.bat now supports display of menu options based on user groups!
Antonio designed AutoMenu.bat to have these information in the filename/directory name (delimited by a minus sign '-'):
key to press-short description-long description
I changed this to:
key to press-privilege (group)-short description-long description (long description can have a minus sign in it - it will be displayed)
My design at the moment has 10 groups (0-9).
Menu options for group 0 are visible to everyone, group 9 is for administrators.
Each user can be a member of only *one* group.
AutoMenu.bat checks for privileges in folder (directory) names and in filenames. Privilege 9 is added by default so Admins can see everything.
Usernames with dedicated privileges (groups) are at the end of the AutoMenu.bat - there's no need to have user's with privilege 0 listed. Users probably don't have write access to AutoMenu.bat so I guess it is sufficient to have this list in the .bat itself.
Code: Select all
REM usernames with privileges
UUUUU#username2#2#
UUUUU#username9#9#
UUUUU#username1#1#
Folder/file privileges can have multiple values. For example if a specific option should be displayed for groups 1 and 2 then privilege 12 is in the file/folder name:
Code: Select all
1-12-Financial Report-Executes a program to generate a financial report
Code: Select all
@echo off
md "TEST FOLDER\1-0-option 1-description for option 1-privilege 0"
>"TEST FOLDER\1-0-option 1-description for option 1-privilege 0\1-0-option-bat.bat" (echo echo inside bat ^%%0)
md "TEST FOLDER\2-1-option 2-description for option 2-privilege 1"
>"TEST FOLDER\2-1-option 2-description for option 2-privilege 1\2-1-option-bat.bat" (echo echo inside bat ^%%0)
md "TEST FOLDER\2-1-option 2-description for option 2-privilege 1\1-1-option 2_1-description for option 2_1-privilege 1"
>"TEST FOLDER\2-1-option 2-description for option 2-privilege 1\1-1-option 2_1-description for option 2_1-privilege 1\1-1-option-bat.bat" (echo echo inside bat ^%%0)
md "TEST FOLDER\3-12-option 3-description for option 3-privileges 1 and 2"
>"TEST FOLDER\3-12-option 3-description for option 3-privileges 1 and 2\3-12-option-bat.bat" (echo echo inside bat ^%%0)
md "TEST FOLDER\4-9-option 4-description for option 4-privilege 9"
>"TEST FOLDER\4-9-option 4-description for option 4-privilege 9\4-9-option-bat.bat" (echo echo inside bat ^%%0)
Code: Select all
AutoMenu.bat "TEST FOLDER"
or you can simulate user 'username1' (with group access 1):
Code: Select all
AutoMenu.bat "TEST FOLDER" username1
And AutoMenu.bat V2.0:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem ==================================================================
rem Automatic multi-level multi-option menu system
rem
rem Antonio Perez Ayala - 09-feb-2022
rem version 1.2 - 12-feb-2022
rem ------------------------------------------------------------------
rem Saso Tomat version 1.3 - 26-jun-2024
rem - added option for translation
rem - added .cmd as supported file type
rem - added @echo off when called .bat returns and has echo set to ON
rem (for example for debugging purposes)
rem - changed action from 'type' to 'more' for .txt files
rem ------------------------------------------------------------------
rem Saso Tomat version 1.4 - 14-aug-2024
rem - to exit main menu key 0 was replaced by X (userdefined)
rem (prevents exit from the main menu when
rem pressing 0 to exit submenus)
rem ------------------------------------------------------------------
rem Saso Tomat version 1.5 - 21-oct-2024
rem - added an option to choose CHOICE.EXE or SET /P
rem ------------------------------------------------------------------
rem Saso Tomat version 2.0 - 28-jul-2025
rem - added a group-based display of menu options
rem ==================================================================
rem https://www.dostips.com/forum/viewtopic.php?f=3&t=10377
rem ==================================================================
rem below you can choose to use CHOICE.EXE or SET /P
rem valid options are 0 and 1
set use_choiceexe=1
rem ==================================================================
rem set use_choiceexe to 1 if wrong value has been set above
if not "%use_choiceexe%"=="1" if not "%use_choiceexe%"=="0" set use_choiceexe=1
rem ==================================================================
rem translation of necessary text
rem (for users to see - everything else remains in English)
rem ==================================================================
REM Letter to exit main menu
set "LetterToExitMainMenu=X"
REM Second SET could be used for translation
set "ChoiceExeText=Select the desired option ("
set "ChoiceExeText=Select the desired option ("
REM Second SET could be used for translation
set "notexist=Menu folder %1 does not exist."
set "notexist=Menu folder %1 does not exist."
REM Second SET could be used for translation
REM 'exit' text should not exceed the length of the 'go back' text
set "textChoice=0 to go back|%LetterToExitMainMenu% to exit"
set "textChoice=0 to go back|%LetterToExitMainMenu% to exit"
rem ==================================================================
rem Get text lengths of both 'go back' and 'exit' options.
for /f "tokens=1,2 delims=|" %%f in ("%textChoice%") do (
>len1.tmp (echo %%f)
>len2.tmp (echo %%g)
)
for %%f in (len1.tmp) do set /a len1=%%~zf - 1
for %%f in (len2.tmp) do set /a len2=%%~zf - 1
if exist len1.tmp del len1.tmp
if exist len2.tmp del len2.tmp
REM line below checks if the 'exit' option text is longer than the 'go back' option text
REM to prevent unwanted displaying of text. Comment IF below if this check is not needed.
if %len2% GTR %len1% echo Second 'TextChoice' string ('exit' string) should be shorter.&pause&goto :EOF
set privs=0
set usern=%username%
if not "%2"=="" set usern=%~2
REM get user's privileges (group)
REM UUUUU#username#privilege (group)#
for /f "tokens=3 delims=#" %%f in ('findstr /I /B /C:"UUUUU#%usern%#" %~f0') do set "privs=%%f"
if "%~1" neq "" if "%~1" neq "/?" goto begin
echo Activate a multi-level multi-option menu system
echo/
echo %~NX0 menuFolder
echo/
echo The menu is defined into menuFolder via subfolders, .txt and .bat files.
echo The names of these elements must have this format:
echo K-NAME-Description of this option
echo where "K" is a character used in CHOICE.EXE to select this option.
echo/
echo Review the extensive example at "Windows-DOS Commands Help" folder.
goto :EOF
:begin
rem Select menu folder and get its name for title and header
if not exist "%~1\" echo %notexist%& goto :EOF
set "title=%~N1"
set "header[0]="
for /L %%i in (0,1,80) do if "!title:~%%i,1!" neq "" set "header[0]=!header[0]! !title:~%%i,1!"
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do set "header[0]=!header[0]:%%a=%%a!"
set "spaces= "
set "action[.txt]=more"
set "action[.bat]=call"
set "action[.cmd]=call"
color 1F
set "level=0"
call :nextLevel %1
color
cls
goto :EOF
:nextLevel subFolder
rem Enter next subFolder level and get directories, .txt, .cmd and .bat files
setlocal EnableDelayedExpansion
cd %1
for /F "delims==" %%a in ('set option[ 2^>NUL') do set "%%a="
set "choices= 0"
if "%level%"=="0" set "choices= %LetterToExitMainMenu%"
set "maxLen=0"
set "spc= "
REM FOR /F below: a=option (key to press), b=privilege (group), c=short description, d=long description
REM key-group-short description-long description
for /F "tokens=1,2,3* delims=-" %%a in ('dir /B *. *.txt *.bat *.cmd') do (
set privs_dir=9%%b
echo !privs_dir!|findstr /c:"!privs!">nul 2>nul
set errlev=!errorlevel!
if "!privs_dir!"=="90" set errlev=0
if "!errlev!"=="0" (
set "choices=!choices!%%a"
set "option[%%a]=%%c"
for /L %%i in (!maxLen!,1,40) do if "!option[%%a]:~%%i,1!" neq "" set "maxLen=%%i" & set "spc=!spc! "
set "descrip[%%a]=%%d"
set "priv[%%a]=%%b"
if "!descrip[%%a]:~-4,1!" equ "." (set "type[%%a]= ") else set "type[%%a]=>"
)
)
set /A maxLen+=2
for /F "tokens=2 delims=[]" %%a in ('set option[') do (
set "show[%%a]=!option[%%a]!%spc%"
set "show[%%a]= !show[%%a]:~0,%maxLen%!"
)
:thisLevel
rem Show menu options at this level
title !title!
cls
echo/
echo/ !usern! %header[0]%
echo/
for /L %%i in (1,1,%level%) do (
set /A "spc=%%i*3"
for %%n in ("!spc!") do echo !spaces:~%%~n!!header[%%i]!& echo/
)
for /F "tokens=2 delims=[]" %%a in ('set option[') do (
for %%b in ("!descrip[%%a]!") do echo !type[%%a]! %%a-!show[%%a]! %%~Nb
)
echo/
rem Select option and activate it: open subfolder or: show .txt file / run .bat or .cmd file
set /A "cho=^!level * len1"
call set textChoice0=!textChoice:~%cho%,%len1%!
if "%use_choiceexe%"=="0" (
REM set default selection as $ - so just pressing ENTER does nothing
set "choice=$"
REM set "choice=!choices:~1,1!"
REM if you want default selection to be 'LetterToExit' or 0 uncomment the SET line above
set /p "choice=!ChoiceExeText!!textChoice0!): "
set "choice=!choice: =!"
if not "!choice:~1,1!"=="" goto :thislevel
set "choice=!choice:~0,1!"
for %%w in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do call set "choice=%%choice:%%w=%%w%%%"
call set choicetmp=%%choices:!choice!=%%%
if "!choicetmp!"=="!choices!" goto :thislevel
) else (
choice.exe /N /C %choices% /M "!ChoiceExeText!!textChoice0!): "
call set "choice=%%choices:~!errorlevel!,1%%%"
)
if not "%level%"=="0" if "%choice%"=="0" exit /B
if "%level%"=="0" if /I "%choice%"=="%LetterToExitMainMenu%" exit /B
set "option=!option[%choice%]!"
set "lastTitle=%title%"
set "title=%title% > %choice%-%option%"
title !title!
set "descrip=!descrip[%choice%]!"
set "priv=!priv[%choice%]!"
set /A "level+=1"
for %%a in ("%descrip%") do set "header[%level%]=%choice%- %option% %%~Na"
if "%descrip:~-4,1%" neq "." (
call :nextLevel "%choice%-%priv%-%option%-%descrip%"
) else (
rem If you want to preserve full menu on screen while a .bat or .txt run, cancel next IF:
if CLEAR == CLEAR (
cls
echo/
echo/ !usern! %header[0]%
echo/
for /L %%i in (1,1,%level%) do (
set /A "spc=%%i*3"
for %%n in ("!spc!") do echo/& echo !spaces:~%%~n!!header[%%i]!
)
)
echo/
!action[%descrip:~-4%]! "%choice%-%priv%-%option%-%descrip%"
@echo off
echo/
title Press any key to return to the menu.
echo Press any key to return to the menu.
pause
)
set /A "level-=1"
set "title=%lastTitle%"
goto thisLevel
REM usernames with privileges
UUUUU#username2#2#
UUUUU#username9#9#
UUUUU#username1#1#
Update 12-aug-2025. added additional code to display username in submenus.
Saso