Solved

Need to create user menu

Posted on 2007-11-23
8
81 Views
Last Modified: 2014-11-21
How do I create a user menu where the bat file asks for info such as name, etc., and then let the person type in the answer which will be saved in the set feature of the .bat file?  

0
Comment
Question by:ttranscripts2
8 Comments
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
You can prompt the user with the set /p command:

set /p ans=Continue Y/N?

if "%ans%"=="" goto :EOF
0
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 250 total points
Comment Utility
Just some sample code to show a menu and get an answer :

echo off
set myvar=
echo pick which one you want?:
echo A ( apples )
set avar=Apples
echo B ( Beauties )
set bvar=Beauties
echo C ( computers )
set cvar=Computers
set /p myvar="Enter your choice (A/B/C):"
echo %myvar%
echo Your Selection is:
if "%myvar%" == "A" ( echo %avar% )
if "%myvar%" == "B" ( echo %bvar% )
if "%myvar%" == "C" ( echo %cvar% )

Thanks
0
 
LVL 3

Expert Comment

by:top_gizmo
Comment Utility
For what you want, you may need to go to a simple vbscript.  It is way more dynamic and you can save the variable "name" etc into a file to retrieve later.  If you want an actual GUI, I would look at AutoIt from www.hiddensoft.com its Free.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 11

Expert Comment

by:paultomasi
Comment Utility
The easy part is getting stuff in.

There are TWO difficult parts:

   1. (and I can't emphasise this enough) anticipating what the user will enter at the keyboard

   2. validating the data entered by the user

In short, things never go wrong until they are in the hands of the user!

Let me add just one more thought to this.

Anticipating what the user will enter is NOT the same as expecting what the user will enter.

For example, suppose you want the user to enter a name such as JOHN SMITH.

The user doesn't know how the data is handled by your batch file so he thinks nothing of entering something like JOHN F SMITH or J SMITH or even J F SMITH. How about J. F. SMITH or even J.F.SMITH.

Suppose he accidentally hits the '#' key when pressing ENTER. You end up with something like JOHN SMITH#.
0
 
LVL 11

Expert Comment

by:paultomasi
Comment Utility
ttranscripts2
nav_kum_v

I prefer to use  arrays for lists and menus. Run the following code for an example.



@echo off
setlocal enabledelayedexpansion
set fruit[1]=Apple
set fruit[2]=Banana
set fruit[3]=Cranberry
set fruit[4]=Date

echo.
for /l %%i in (1,1,4) do echo %%i. !fruit[%%i]!

echo.
set /p choice=Select fruit [1-4]:

echo.
echo You chose !fruit[%choice%]!


0
 
LVL 10

Expert Comment

by:ReneGe
Comment Utility
How about this?

Cheers,
Rene

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

SET Database=%~n0.txt
SET Data.ROW1=First Name
SET Data.ROW2=Last Name
SET Data.ROW3=Age
SET Data.ROW4=Magic Number

:Home
CLS
CHOICE /M "DO YOU WISH TO CREATE A NEW USER?"
IF %errorlevel% == 2 GOTO DisplayData


:NewUser
CLS
IF "%TheUser%" NEQ "" (ECHO LAST USER ENTERS WAS: [%TheUser%] & ECHO.)
ECHO PLEASE ENTER USER INFORMATION AS FOLLOWES
ECHO FIRST NAME,LAST NAME,AGE,MAGIC NUMBER
SET /P TheUser=
REM IF NAME DOES NOT EXIST, ADD IT TO THE DATABASE 
	IF NOT EXIST "%Database%" (
		ECHO %TheUser%>>%Database%
	) ELSE (
	FINDSTR -i /C:"%TheUser%" %Database% >NUL || ECHO %TheUser%>>%Database%
	)
ECHO.
CHOICE /M "DO YOU WISH TO CREATE A NEW USER?"
IF %errorlevel% == 1 GOTO NewUser



:DisplayData
REM READING USERS IN THE DATABASE TO ARRAY
	FOR /F "TOKENS=1-4 DELIMS=," %%A IN (%Database%) DO (
		SET /a UserNb+=1
		SET Data.ROW1.!UserNb!=%%A
		SET Data.ROW2.!UserNb!=%%B
		SET Data.ROW3.!UserNb!=%%C
		SET Data.ROW4.!UserNb!=%%D
	)

REM CHOOSING WHAT USER IS TO BE DISPLAYED
	ECHO PLEASE CHOOSE WHAT USER YOU WISH TO DISPLAY INFORMATION
	ECHO -------------------------------------------------------
	FOR /L %%A IN (1,1,%UserNb%) DO (
		ECHO %%A- !Data.ROW1.%%A! !Data.ROW2.%%A!
		SET Choices=!Choices!%%A
	)
	ECHO.
	CHOICE /C %Choices%
	ECHO.

REM DISPLAYING THE CHOOSEN DATA
	ECHO.
	ECHO.
	ECHO USER DATA
	ECHO -------------------------------------
	ECHO %Data.ROW1%: !Data.ROW1.%errorlevel%!
	ECHO %Data.ROW2%: !Data.ROW2.%errorlevel%!
	ECHO %Data.ROW3%: !Data.ROW3.%errorlevel%!
	ECHO %Data.ROW4%: !Data.ROW4.%errorlevel%!
	ECHO.

PAUSE
EXIT

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now