Question Locked

Autoexec.bat

0 helpful
11 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Im trying to make me a bootable thumb drive.
Which I can..no problem. I want a menu to select from. Im editing the autoexec.bat file here is what i have so far....

@echo off
prompt $p$g

:menu
cls
echo 1.DOS
echo 2.AutoClave
echo 3.Ghost
set /p choice=?:

if "%choice%" == "1" goto DOS
if "%choice%" == "2" goto AutoClave
if "%choice%" == "3" goto Ghost
(echo Error: Invalid choice. && pause) & (goto menu)

:DOS
cd \DOS\AUTOEXEC.BAT
goto exit

:AutoClave
cd \AutoClave\AUTOEXEC.BAT
goto exit

:Ghost
cd \Ghost\AUTOEXEC.BAT
goto exit

:exit

.... most of it work fine execpt it errors out on this line (echo Error: iInvalid choice. && pause) & (goto menu).

The error message reads
"Bad command or file name
invalid directory"

One more thing it runs fine throught the command prompt just not when I boot from a disk. The boot screen look like this...

1.DOS
2.AutoClave
3.Ghost
Bad command or file name
invalid directory
A:\>

Any help would be super Appreciated

11 replies

by rob miners

:: I modified this file to open Notepad.exe as an example.
:: Cut Below and rename the file to menu.bat and call it from autoexec.bat
============================================================

@ECHO OFF
CLS
:LOOP
:: ECHO A. Menu item A
ECHO A. NOTEPAD
ECHO B. Menu item B
ECHO C. Menu item C
ECHO Q. Quit
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO NOTEPAD
IF /I '%Choice%'=='B' GOTO ItemB
IF /I '%Choice%'=='C' GOTO ItemC
IF /I '%Choice%'=='Q' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:NOTEPAD
:: ECHO Insert commands for Item A.
C:\WINDOWS\NOTEPAD.EXE
GOTO Again
:ItemB
ECHO Insert commands for Item B.
GOTO Again
:ItemC
ECHO Insert commands for Item C.
GOTO Again
:Again
PAUSE
CLS
GOTO Loop
:End

< It is better to keep the Menu separate from Autoexec.bat > ;)

If you want to add a bit of colour to the Menu.

http://kb.iu.edu/data/aamm.html

by dkittle

Well I tried it and it's no working here is what I have.

This works?
autoexec.bat

call menu.bat

I tried to simplify the process by going to 1 directory.

Whats happening is it's just looping over and over.

Its displaying?
A ghost
Q quit
"" is not valid. Please try again.

Over and over

menu.bat

@ECHO OFF
CLS
:LOOP
:: ECHO A. Menu item A
ECHO A. ghost

ECHO Q. Quit
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO ghost

IF /I '%Choice%'=='Q' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:ghost
:: ECHO Insert commands for Item A.
cd \Ghost
call AUTOEXEC.BAT
GOTO Again

:Again
PAUSE
CLS
GOTO Loop
:End

Any help would be appriciated

by rob miners

When you have the Menu running don't call Autoexec.bat as it is only used for startup.
Notice that I have included a drive letter E:
if the ghost file is in the root it would be C:

@ECHO OFF
CLS
:LOOP
:: ECHO A. Menu item A
ECHO A. ghost
ECHO Q. Quit
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO ghost
IF /I '%Choice%'=='Q' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:ghost
:: ECHO Insert commands for Item A.
E:
cd Ghost
Ghost
GOTO Again

:Again
PAUSE
CLS
GOTO Loop
:End

by dkittle

it's doing the same thing.

I copied what youd had here and changed e: to c:

and added start ghost.exe

same error as last time it keeps on looping its self.

by rob miners

isn't in a folder remove the reference cd Ghost

E:
cd Ghost
Ghost.exe

E:
Ghost.exe

by dkittle

It all works from the command prompt ?!?

When booting however..
Its acting like I've enter a choice (which i haven't) and starting the loop over.

by rob miners

Operating System are you booting from.
Post a copy of your Config.sys
Post a copy of your Autoexec.bat
and your new Menu.

by dkittle

ok...
It said I had reached the max posts?
I don't want ghost to start up right away. I want to be able to pick from a few options.
I copied your original menu script and changed every thing you said to.

it reads
@ECHO OFF
CLS
:LOOP
:: ECHO A. Menu item A
ECHO A. Ghost
ECHO B. Menu item B
ECHO C. Menu item C
ECHO Q. Quit
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO Ghost
IF /I '%Choice%'=='B' GOTO ItemB
IF /I '%Choice%'=='C' GOTO ItemC
IF /I '%Choice%'=='Q' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:Ghost
C:
cd Ghost
Ghost.exe
GOTO Again
:ItemB
ECHO Insert commands for Item B.
GOTO Again
:ItemC
ECHO Insert commands for Item C.
GOTO Again
:Again
PAUSE
CLS
GOTO Loop
:End

When I boot from the disk it loops over and over it doesn?t stop. Its acting like I selected an invalid option and returning to the start of the loop. I inserted pause statements under each line and its erroring out here ECHO "%Choice%" is not valid. Please try again.
ECHO.

Thx again for you help

This discussion is closed to new replies.