Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello.
I've just registered and wondered if you fine people could help me out on a simple batch script programme. I've never done any before and I have to write one that uses the below ideas:
Create a new batch file that will use one of the following commands:
1. net name
2. dir c:\
3. echo finishedThe programme supplied will prompt the user to select one of the options from the above list. Once the selection is made the programme will run the selected command. This will be repeated until the user selects the “finish” (3rd) option.
Can any of you help me write this programme, I haven't got much time to work on it so any help would be much appreciated.
Many Thanks
Mike Allen

Hio Mike,
Try this:
::==
@echo off
clsecho 1. net name
echo 2. dir c:\
echo 3. echo finishedchoice /c123 Pleasease choose
goto %errorlevel%
:1
echo here's 1
:: take out the line above and put in your command
goto :eof:2
echo here's 2
:: take out the line above and put in your command:3
:eof
::==M2
If at first you don't succeed, you're about average.

Well...
On second thought, this is probably what you want:
::==
@echo off
clsecho 1. net name
echo 2. dir c:\
echo 3. finished
echo.choice /c123 Pleasease choose
goto %errorlevel%
:1
net name
goto :eof:2
dir c:\
goto :eof:3
echo finished
:eof
::==M2
If at first you don't succeed, you're about average.

Hi
I've tried both of those and nothing happens - I'm sorry but can you please run through it step by step of what to do and what to include.
Many Thanks
Mike

When I wrote the script out in Notepad and then saved it, should I leave the default as .txt or add exe at the end as others have done that.
And then they just double click on the exe file and it runs.

Hi Mike,
In order for a batch file to work, it needs to be named blabla.BAT, like:
Mikes.BAT
123.BAT
etc
M2
If at first you don't succeed, you're about average.

Hi
I've done that and copied your code from the second example and again it runs and then straight away ends.

Hi Mike,
What is on the screen after it runs?
M2
If at first you don't succeed, you're about average.

Hi
Nothing - it appears then disappears in a second so I can't see what is on the screen :-(
Mike

OK,
What's on the screen before you run it?
M2
If at first you don't succeed, you're about average.

In the folder it's saved it just the name of the file and reads ms dos batch file
and when I click on it it appears and within a second disappears and I don't have time to read what is on it.

To get it to work on my system I had to include the path to the Choice command. I also inserted a couple of Pauses to allow you to verify the successdful completion.
@echo off
cls
echo 1. net name
echo 2. dir c:\
echo 3. finished
echo.
c:\windows\command\choice /c123 Please choose
goto %errorlevel%
:1
net name
goto :eof
:2
dir c:\
Pause
goto :eof
:3
echo finished
Pause
:eof

Hi
So if I copy and paste this into notepad and save it as a batch file it should work succesfully?
Thanks for this again and for being very patient with me.
Mike

Hi Mike,
#7 refers you to reply 7 where I said you need to go to a command prompt.
That's the only way to get it working right.
M2
If at first you don't succeed, you're about average.

Copy it into Word Pad and not Note Pad. Then select "Save As".
Make the File Name any name you want but the extenstion must be ".bat"
Change the Save AS Type to "Text Document-MS DOS Format"
Save the file and then go to the location you saved it and double click on it to execute.

Hi The,
He's been clicking on it for a few days. That's the problem. Not the solution.
Difficult to figure what advantage wordpad might bring to this saga. 21 and counting.
M2
If at first you don't succeed, you're about average.

The copy and paste option eliminates typos. Without the path to the choice command the batch file just flashes on the screen for a split second and aborts without any error or indication why.
Using NotePad won't work because it doesn't offer the option of saving the file in a "Document Text-MS DOS Format" whereas Word Pad does.

Hi The,
Interesting point about WP / NP.
Seems many, many folks have used NPt for the "text editor" of choice for a long time.
Windows also has "EDIT", FWIW; I never use it.
I use a real DOS text editor.
You're correct in guessing that CHOICE may not be in the path. Hard tellin' where it might be.
But if CHOICE is not in the path, you'll get an error.
That's why I'm trying to get Mike to run it from a prompt.
M2
If at first you don't succeed, you're about average.

I typed it out in wordpad and saved it as a text document-MS Dos format.
I double click on the file and it opens but under the options it reads:
"The System cannot find the path specified
finished
press any key to continue.."When I type in 1 or 2 or 3 it just ends!
:-(
Thanks for the help again on this batch file - I have two weeks to make sure it runs succesfully :-)

Do a search for "choice" on your system and note the path to it when found. Modify the instructions in the Bat file with the path you found.

If you have Win 2k or XP you may have to use the set command:
@ECHO off
cls
:start
ECHO.
ECHO 1. net name
ECHO 2. dir c:\
ECHO 3. Finish
set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto 1
if '%choice%'=='2' goto 2
if '%choice%'=='3' goto 3
ECHO "%choice%" is not valid please try again
ECHO.
goto start
:1
net name
goto start
:2
dir c:
goto start
:3
goto end
:end
ECHO Program Closed.

![]() |
![]() |
![]() |

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