Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi guys, got a kinda big problem. my idea is to make a menu at first so you can choose a category and then come to the category. But when i press "m" i still come to the first menu where you can choose to open apps and when you push "enter" and you havent typed in a number it comes back to the main menu. even if you choose a program it comes back to the main menu.
My code is probably messed up cause i played with it a bit but i really need hellp guys !
So short: I whant to be able to make my menu and make SUB menus later from it. so plz help.
Oh and by the way, i whant this to work for people that uses vista too if that helps any.Code:
@echo off
cls
color A
title Arams Hjalp
:MAIN 1
cls
echo Skriv vilken siffra du vill ha och tryck sen ENTER
echo Tryck p for att oppna olika program
echo Tryck m for att oppna olika mappar
echo Tryck h for att oppna olika hemsidor
pause
choice /C:pmh /n Ditt val:
IF '%VAR%' == 'p' GOTO program
IF '%VAR%' == 'm' GOTO mappar
IF '%VAR%' == 'h' GOTO hemsidor
echo Skriv din siffra
cls:program
:MAIN
echo skriv 1 for att stanga ner denna ruta
echo skriv 2 for att oppna Paint
echo skriv 3 for att oppna Internet Explorer
echo skriv 4 for att oppna Utorrent
echo skriv 5 for att oppna Mozilla Firefox
echo skriv 6 for att oppna Windows Update
echo skriv 7 for att oppna Msn Messenger (dock inte 7.5 och gammlare)
echo skriv 8 for att oppna Anteckningar
echo skriv 9 for att oppna Diskrensning
echo skriv 10 for att oppna Windows Media Player
echo skriv 11 for att oppna Skarmtangentbord
echo skriv 12 for att oppna Skarmforstoraren (dra den lite nerat sa den blir storre)
echo skriv 13 for att oppna kalkylatorn
echo skriv 14 for att logga ut denna anvandare
echo skriv 15 for att oppna Windows Movie Maker
echo skriv 16 for att oppna WinRAR
echo skriv 17 for att komma tillbaka till huvudmenynecho GJORD AV : ARAM
set /p var=Skriv vilken siffra du vill:IF '%VAR%' == '1' GOTO stäng
IF '%VAR%' == '2' GOTO paint
IF '%VAR%' == '3' GOTO internet
IF '%VAR%' == '4' GOTO utorrent
IF '%VAR%' == '5' GOTO firefox
IF '%VAR%' == '6' GOTO update
IF '%VAR%' == '7' GOTO messenger
IF '%VAR%' == '8' GOTO notepad
IF '%VAR%' == '9' GOTO diskrensning
IF '%VAR%' == '10' GOTO mediaplayer
IF '%VAR%' == '11' GOTO skärm
IF '%VAR%' == '12' GOTO hjälp
IF '%VAR%' == '13' GOTO calc
IF '%VAR%' == '14' logoff
IF '%VAR%' == '15' GOTO movie
IF '%VAR%' == '16' GOTO winrar
IF '%VAR%' == '16' GOTO MAIN 1echo GJORD AV : ARAM
goto :MAIN:calc
%SystemRoot%\system32\calc.exe
goto :MAIN:paint
%SystemRoot%\system32\mspaint.exe
goto :MAIN:internet
"C:\Program\Internet Explorer\iexplore.exe"
goto :MAIN:utorrent
"C:\Program\uTorrent\uTorrent.exe"
goto :MAIN:firefox
"C:\Program\Mozilla Firefox\firefox.exe"
goto :MAIN:update
%SystemRoot%\system32\wupdmgr.exe
goto :MAIN:messenger
"C:\Program\Windows Live\Messenger\msnmsgr.exe"
goto :MAIN:notepad
%SystemRoot%\system32\notepad.exe
goto :MAIN:diskrensning
%SystemRoot%\system32\cleanmgr.exe
goto :MAIN:mediaplayer
"C:\Program\Windows Media Player\wmplayer.exe"
goto :MAIN:skärm
%SystemRoot%\system32\osk.exe
goto :MAIN:hjälp
%SystemRoot%\system32\magnify.exe
goto :MAIN:stäng
EXIT
goto :MAIN:movie
"C:\Program\Movie Maker\moviemk.exe"
goto :MAIN:winrar
C:\Program\WinRAR\WinRAR.exe
goto :MAIN:musik
%windir%\explorer.exe "%userprofile%\Mina dokument\Min musik\
goto:MAIN:mappar
:LOLecho skriv 1 for att stanga ner denna ruta
echo skriv 2 for att oppna Mina Dokument
echo skriv 3 for att oppna
echo skriv 4 for att oppna
echo skriv 5 for att oppna
echo skriv 6 for att oppna
echo skriv 7 for att oppna
echo skriv 8 for att oppna
echo skriv 9 for att oppna
echo skriv 10 for att oppna
echo skriv 11 for att oppna
echo skriv 12 for att oppna
echo skriv 13 for att oppna
echo skriv 14 for att logga
echo skriv 15 for att oppna
echo skriv 17 for att oppnaecho GJORD AV : ARAM
set /p var=Skriv vilken siffra du vill:IF '%VAR%' == '1' GOTO stäng
IF '%VAR%' == '2' GOTO paint
IF '%VAR%' == '3' GOTO internet
IF '%VAR%' == '4' GOTO utorrent
IF '%VAR%' == '5' GOTO firefox
IF '%VAR%' == '6' GOTO update
IF '%VAR%' == '7' GOTO messenger
IF '%VAR%' == '8' GOTO notepad
IF '%VAR%' == '9' GOTO diskrensning
IF '%VAR%' == '10' GOTO mediaplayer
IF '%VAR%' == '11' GOTO skärm
IF '%VAR%' == '12' GOTO hjälp
IF '%VAR%' == '13' GOTO calc
IF '%VAR%' == '14' logoff
IF '%VAR%' == '15' GOTO movie
IF '%VAR%' == '16' GOTO winrar
IF '%VAR%' == '17' GOTO musik:musik
%windir%\explorer.exe "%userprofile%\Mina dokument
goto:LOL

choice /C:pmh /n Ditt val:
IF '%VAR%' == 'p' GOTO program
IF '%VAR%' == 'm' GOTO mappar
IF '%VAR%' == 'h' GOTO hemsidorFirstly choice isn't available on xp unless you bring the execuatble with the script (or in a rare case someone has already added the executable to the machine).
If you insist in using choice you would need to use it correctly, choice uses errorlevels to identify what character was entered. These errorlevels are set according to the position after "/c:" the first character will be 1, the second will be 2 and so on, in the above example "h" would return an errorlevel of 3.
Their are two main way to test the errorlevel.
if %errorlevel%==<number> commandor
if errorlevel <number> commandA third way is to use number labels and:
goto %errorlevel%An important thing to note about "if errorlevel <number>" is that it tests that the errorlevel is greater than or equal to the number so the commands must be in reverse order and, e.g:
if errorlevel 5 goto fake5 if errorlevel 4 goto anotherfakeYou also use "set /p" in your script you could replace the choice command with "set /p var=" but you will need to modify the if statements so they are case insensitive so that caps lock don't kill your script:
IF /i "%VAR%"=="p" GOTO programAlso it is important to ensure that nothing slips through from set /p because if your not careful people can get commands to execute using ampersands:
:loop
set var=
Set /p var=Ditt val:
IF /i "%VAR%"=="p" GOTO program
IF /i "%VAR%"=="m" GOTO mappar
IF /i "%VAR%"=="h" GOTO hemsidor
cls
echo ???
goto loop

Okay thank you ! That fixed the menu problem. But now for the other problem; When i press "m" to come to "directorys" and i just press enter without typing something in "My Documents" still opens ! How do i fix that ?
The GOTO MAIN fixed all of that before, thats why I put :LOL under :program so you could come back to the menu when you typed in an directory.

The program flows from top to bottom unless you direct it by goto's, for loops or code blocks, so if none of your conditions are met then the flow falls through, in you case straight into the "my documents" section. A "goto mapper" after your last condition sends the flow back to the mapper label if the string was blank or unrecognised.
... IF "%VAR%"=="17" GOTO musik cls goto mapper ...Also it's a good idea to use double quotes rather than single quotes as it will give a lower chance of failure when people type weird things into the set /p prompt.
Another thing to note is that if the variable your using with set /p is already set only hitting enter will leave this variable intact, if you don't want default actions then clearing the variable first can avoid unwanted input:
set thisvar= set /p thisvar=Hello!If you want default actions it is also very simple:
set thisvar=3 set /p thisvar=Enter an option or nothing for option 3.

![]() |
Header and trailer for cs...
|
c code
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |