Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One for you script junkies out there 1

Status
Not open for further replies.
May 31, 2006
237
US
There's a lot of really good scripters on this forum, so I'll put this question to you: Back in the DOS days I used the CHOICE command a lot. Since Win98 that command is no longer available in the Windows environment. So how could I write a batch file that would achieve the same result in Windows 2000/XP as the following code:

Code:
echo.
echo 1. Southeast Center
echo 2. Downingtown
echo 3. Exton
echo 4. Malin Rd.
echo 5. Marple
echo.
choice /c:12345q Which campus? (q to quit)
if errorlevel 1 if not errorlevel 2 goto sec
if errorlevel 2 if not errorlevel 3 goto dow
if errorlevel 3 if not errorlevel 4 goto ext
if errorlevel 4 if not errorlevel 5 goto mal
if errorlevel 5 if not errorlevel 6 goto mar
if errorlevel 6 goto done

Also, is there a more elegant way to append to a text file than this (for example):

Code:
echo y | copy %systemroot%\system32\drivers\etc\hosts+sechosts.txt %systemroot%\system32\drivers\etc\hosts

Where "sechosts.txt" contains the hosts entry I'd like to append to the existing hosts file for the Southeast Center.

One other (semi-)related question. I realize after seeing (and using in some cases) some of your batch file code, my batch-scripting skills are way outdated (mostly from pre-DOS 6.22 days). Is there any reference book you would suggest to bring my skillset up to date? Then I could stop asking these mundane questions here (-:

Thanks in advance!
 
Choice.exe is available in the 2000 Resource Kit, as are many other tools that make scripting a little easier. I can't seem to find it on MS any more, I think they've retired it, but you can find it here:


Under the link that says "User Input for Batch Files".

I would suggest getting familiar with VBScript. It's where MS has been heading with scrpting for some time now and it's really not all that hard to learn. I honestly didn't use any books, I just looked at code samples from places like tek-tips and Microsoft and figured out how they worked; some opinions may differ from that approach, though. MS has some good information on getting started and code samples here:
 
That CHOICE.exe works perfectly. I'm gonna have to check out doing some VB scripting (if I can find the time! lol), and that resource looks terrific. Thanks, Chip!
 
vbscript is certainly the way to go. You would simply use a Select Case statement to replace your "choice" command.

You will find examples of all you need in 2 of my FAQs

Implementing Powerful and Flexible Login Scripts
faq329-5798

Scripting for Multiple Physical Locations
faq329-5908.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top