Simple Batch Script help

May 15, 2005 at 03:11:40
Specs: Windows XP, -

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 finished

The 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


See More: Simple Batch Script help

Report •


#1
May 15, 2005 at 04:08:00

Hio Mike,

Try this:

::==
@echo off
cls

echo 1. net name
echo 2. dir c:\
echo 3. echo finished

choice /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.


Report •

#2
May 15, 2005 at 04:15:25

Well...

On second thought, this is probably what you want:

::==
@echo off
cls

echo 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.


Report •

#3
May 15, 2005 at 05:16:00

Thanks for these, I will have a go at it now and I'll get back to you.

Many Thanks again


Report •

Related Solutions

#4
May 18, 2005 at 02:34:18

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


Report •

#5
May 18, 2005 at 02:38:34

Mike,

"nothing happens"

No error, no output?

M2


If at first you don't succeed, you're about average.


Report •

#6
May 18, 2005 at 08:05:08

Hi

No Error Message or Output at all I just double click the program and it just ends.


Report •

#7
May 18, 2005 at 23:58:30

Go to a command prompy and run it.

M2


If at first you don't succeed, you're about average.


Report •

#8
May 19, 2005 at 08:33:30

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.


Report •

#9
May 19, 2005 at 21:56:54

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.


Report •

#10
May 20, 2005 at 06:32:34

Hi

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


Report •

#11
May 20, 2005 at 06:56:33

Hi Mike,

What is on the screen after it runs?

M2


If at first you don't succeed, you're about average.


Report •

#12
May 20, 2005 at 08:35:57

Hi

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

Mike


Report •

#13
May 20, 2005 at 08:50:13

OK,

What's on the screen before you run it?

M2


If at first you don't succeed, you're about average.


Report •

#14
May 20, 2005 at 09:41:52

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.


Report •

#15
May 20, 2005 at 09:47:27

#7

M2


If at first you don't succeed, you're about average.


Report •

#16
May 21, 2005 at 05:26:27

Hi

What does #7 do?


Report •

#17
May 21, 2005 at 13:05:49

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


Report •

#18
May 22, 2005 at 06:04:10

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


Report •

#19
May 22, 2005 at 06:54:42

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.


Report •

#20
May 22, 2005 at 11:21:08

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.


Report •

#21
May 22, 2005 at 11:33:25

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.


Report •

#22
May 22, 2005 at 20:40:02

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.


Report •

#23
May 22, 2005 at 23:35:13

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.


Report •

#24
May 23, 2005 at 00:24:38

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 :-)


Report •

#25
May 23, 2005 at 08:01:05

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.

Report •

#26
June 1, 2005 at 05:56:21

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.


Report •

#27
June 1, 2005 at 22:21:10

In NT choice sets errlevel.



Report •


Ask Question