Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-25-2005, 04:48 AM   #1
Solid State Member
 
Join Date: May 2005
Posts: 9
Default Simple Batch File Help

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. I posted on another forum and their solutions were not working.

Many Thanks

Mike Allen
__________________

Mike_A is offline   Reply With Quote
Old 05-25-2005, 04:48 PM   #2
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Simple Batch File Help

wow what a can of worms that is...

there are a few methods that you can use...
each get steaditly more compilcated than the last...

the first (easiest), is t ave four batch files...

start.bat
Code:
@echo off
REM this is the choices menu
echo 1, print Net name.
echo 2, Print c:\
echo 3, finish.
1.bat
Code:
REM do function
net name
REM call menu
start.bat
2.bat
Code:
dir c:
start.bat
3.bat
Code:
echo press any key to exit...
pause > null
__________________

root is offline   Reply With Quote
Old 05-25-2005, 05:08 PM   #3
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Simple Batch File Help

the second is folowing advice from microsoft

http://support.microsoft.com/default...;EN-US;Q77457&

you have to write your own key trapping program using assenbally language...

this is easier than it sounds...
go to the comand prompt and change to the windows directory (so it'll be in the system path)...

now type the following exactly...#
[enter] means press the return key...

debug reply.com [enter]
a 100 [enter]
mov ah,08 [enter]
int 21 [return]
cmp al,0 [return]
jnz 010a [return]
int 21[return]
mov ah,4c [return]
int 21 [return]
[return]
rcx [return]
e [return]
n reply.com [return]
w [return]

(at this point the program informs you that the program is written and akes E bytes (14 bytes)

q [return] and that quits...

now you are ready to write the batch file...

Code:
@Echo off

:Ask
Echo press 1 to view net name,
Echo press 2 to view contents of C:
Echo press 3 to exit.

Reply

If errorlevel 49 if not errorlevel 50 goto one
If errorlevel 50 if not errorlevel 51 goto two
If errorlevel 51 if not errorlevel 52 goto three

Echo Error wrong Key pressed.
goto ask

:one
NET view
pause > null
goto ask

:two
dir c:
pause > nul
goto ask

:three
   cls
   ver
root is offline   Reply With Quote
Old 05-26-2005, 05:48 AM   #4
Solid State Member
 
Join Date: May 2005
Posts: 9
Default Re: Simple Batch File Help

I tried the first method and only number 2 and three load when I double click on them.

I created all four files in WordPad and typed the code as you did but the start one loads and then disappears as does number 1. Wheres 2 and 3 load but when I try to enter a number or Y or N it says invalid.

Sorry for being such a dumbass but I've never done them before so I have no idea what is going wrong.
Mike_A is offline   Reply With Quote
Old 05-26-2005, 06:20 AM   #5
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Simple Batch File Help

have all four batch file in a single folder.

now run them from the command prompt rather than double clicking the batch file.
the first file start.bat loads and disapears when you double click because it has no real functions, it only displays text. if you run it from the command prompt obviously the text stays around to be seen.

3 only stays around because of the pause function used,

run it all from a command prompt and it'll make sense.
root is offline   Reply With Quote
Old 05-26-2005, 06:59 AM   #6
Solid State Member
 
Join Date: May 2005
Posts: 9
Default Re: Simple Batch File Help

I've go to run and selected the start.bat and as you said it loads then disappears then, number three when selected loads then when I click three it ends but the other two don't work still.
Mike_A is offline   Reply With Quote
Old 05-26-2005, 08:39 AM   #7
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Simple Batch File Help

ok...
now follow the instructions...
opn the command prompt...
navigate to the folder containing the batch files and run the folder called start.bat...

as I said in the previous post, the reason the file start.bat disapears is because it finishes. there is no reason for it to hang about taking up screen space, so it doesn't.

you need to run it from the command prompt (using this method) because you need the text to stay on the screen so you can see what the choices are...
root is offline   Reply With Quote
Old 05-26-2005, 08:43 AM   #8
Solid State Member
 
Join Date: May 2005
Posts: 9
Default Re: Simple Batch File Help

I think for this work we need to click on just one file and then the options all appear and in the same screen then once you type 1 or 2 the c directory is listed and so forth.
Mike_A is offline   Reply With Quote
Old 05-26-2005, 09:02 AM   #9
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Simple Batch File Help

you'll have to go with the second option then...
root is offline   Reply With Quote
Old 05-26-2005, 10:49 AM   #10
BSOD
 
pcmxkeith's Avatar
 
Join Date: Dec 2004
Posts: 842
Send a message via AIM to pcmxkeith Send a message via MSN to pcmxkeith Send a message via Yahoo to pcmxkeith
Default Re: Simple Batch File Help

What exactly are you wantning to do with this script? If you are truing to setup a network i recommend getting your self a server and installing "Kixtart" or Kix32, (login scripts)
__________________

pcmxkeith is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 01:27 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0