Question

DOS batch file with user input variable

Asked by: martinpyt

We are running ACCPAC on Windows workstations on a network. Multiple users, needing to work from any workstation. The program settings are in a directory. The command line that starts the program is something like:

m:\PLUS.EXE /v3 /db /SF:\users\mary\EZS /CF:\users\mary\mcc
 
We would like to replace the "mary" with a variable. We can do that with %1, however:
 
The command or a batch file is attached to an icon on the user's desktop. We would like to have a single icon that runs an identical command line, that asks the user to input their user name, the equivalent of the %1 or "mary".

Can one of you help write a batch that would pop a prompt on the screen "User name, please:" and once the user typed in "mary" it would run the next batch file with "mary" substituting the "%1" from the above example?

Thanks. Martin

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2002-10-25 at 10:33:54ID20382358
Tags

batch

,

input

,

file

,

dos

,

user

Topic

MS DOS

Participating Experts
6
Points
100
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. passing Cf Variables to this.
    I currently have an application that prints out badges to a Zebra Printer. I have found the file withing the application that Pulls and formats the badge for print. It currently is not CF enabled but am in the process of testing and making it so.. Is their a way to have CF ...
  2. Dynamically generate batch files with CF?
    Hello, I have the task of automating a previously manual process, one step of which is to load the contents of a .dat file into the Oracle DB using sqlldr. (This .dat file is coming from an SAP system that is behind the firewall, and there is no way that I can change that pr...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: dreffedPosted on 2002-10-25 at 11:13:20ID: 7370404

Hi Martin

Are you using Windows NT?
otherwise you could try this link
http://www.roanoke.infi.net/~wtnewton/batch/batchfaq.html#12

 

by: dbruntonPosted on 2002-10-25 at 11:16:54ID: 7370420

You will need the following util


 ftp://ftp.zdnet.com/pcmag/1992/1222/strings.zip

Place the strings.com file in your path somewhere, then the batch file becomes

@echo off
cls
strings NAME = ask Please enter your name
m:\PLUS.EXE /v3 /db /SF:\users\%NAME%\EZS /CF:\users\mary\mcc

 

by: vinnyd79Posted on 2002-10-27 at 17:31:20ID: 7376654

could you launch it from a vbscript file? Try adding this to a text file then save it with a ".vbs" extension.
This will pop up a window asking for name,then pass it to your batch file so you can use it as %1.


Dim usrName
usrName = Inputbox("Enter User Name","Enter Name")

Set WShell = CreateObject("WScript.Shell")
WShell.Run "c:\accpac.bat " & usrName

 

by: rin1010Posted on 2002-10-27 at 18:30:40ID: 7376781


Martin,

You said, "...once the user typed in "mary" it would run
the next batch file with "mary" substituting the "%1" ..."

Do you mean that you have two batch files and that you need to
prompt for the replaceable parameter from the first batch file
and pass the %1 parameter to the second batch file?

You mention that the "batch file is attached to an icon on the user's desktop"
and that you'd "like to have a single icon that runs an identical command line,
that asks the user to input their user name, the equivalent of the %1 or 'mary'."

If you use a batch file having that particular command line
and an icon link to the batch file on the desktop,
you can create a PIF for the batch file
to generate a prompt when run.

Right-click on the batch file's Desktop icon
and from the ensuing menu choose Properties...

In the "Cmd Line" field on the Program tab
will be the path and name of the batch file.

Insert a space and a question mark after the name of the batch file.

For example, if the batch file is named "usrprmpt.bat"
you would append the question mark so that it reads:

usrprmpt.bat ?

Now when you launch the batch file from the Desktop icon
a dialog box will appear prompting for user input...
The input will be passed to the batch file
as the %1 replaceable parameter.

Your batch file will contain the command line
as in your example with syntax similar to this:

m:\PLUS.EXE /v3 /db /SF:\users\%1\EZS /CF:\users\%1\mcc

The batch file can also contain error checking
to ensure input was provided at the prompt...

The user input can also be set to an environment variable
or passed as a parameter to a second called batch file...

You can further control the batch file's behavior
by creating and then editing its PIF properties...

You can have the batch file "Close on Exit"
or have it run maximized or minimized
or full-screened or windowed, etc...

You can also call another batch file from the "Batch File" field
and the PIF will have other options that may help you with it...

I'll post a batch file example that you can use for testing
if you're interested, for which you can create a Desktop link...
Then right-click on its icon (or the batch file's name in Explorer)
and then add the space and question mark to the end of its name
in the "Cmd Line" field on the Program tab in the PIF properties dialog.

Please post back if this isn't what you mean
and provide whatever other details you can...

This example merely echoes the replaceable parameter to the screen
and then closes the window, but perhaps it will give you some ideas...


::
@echo off
cls
echo.
if "%1"=="" goto usage
echo  You entered:  %1
goto end
:usage
echo Must enter a valid parameter...
:end
echo.
pause
cls
exit
::

 

 

by: martinpytPosted on 2002-10-27 at 21:47:26ID: 7377245

Hi rin1010,
your suggestions are the closest to what I had in mind. I will test the suggested ideas and get back. I like the pif link idea.

I would like to end up with one icon, and one batch file that is run with the parameter the user enters at the prompt.

I will test it and come back. Thanks for everyone's ideas.

Martin

 

by: martinpytPosted on 2002-10-31 at 16:29:18ID: 7394661

I tested the suggestion - the usrprmpt.bat ? was exactly what I needed. Thanks!

 

by: mahender612Posted on 2004-08-05 at 16:26:55ID: 11731731

how to get yesterday's date dynamically in a batch program.


Thanks
Mahi

 

by: microage1Posted on 2008-01-18 at 07:31:59ID: 20691027

Hi

I have this same thing setup for deleting users temporary internet files, I have a variable in my script that asks for a name at the start then puts the name in my %username% code

I start my script with this:

:start
@echo off
echo Please enter your WIndows Login name (Firstname)
set /p Username=

Then i have a menu and an option is to delete temporary internet files here is the code for that

:delfiles
cd \
cd C:\documents and settings\%username%\Local Settings
rd tempor~1 /s/q
echo done
pause
cls
goto start1

I have attached the full code below

Try that and see if it works

@Echo off
 
echo -------------------------------
echo Script by Jason Gudmundson
echo 1.0
echo ------------------------------- 
 
:start
@echo off
echo Please enter your WIndows Login name (Firstname)
set /p Username=
 
:start1
ECHO                              You are at the Main Menu
ECHO 1. Launch Policy Pro
ECHO 2. Launch SmartDraw 7
ECHO 3. Delete Temp Files
ECHO 4. Launch E-Mail
ECHO 5. Launch Microsoft Word
ECHO 6. Start MicroAge remote support
ECHO 7. Change Username
ECHO 8. Re-Map Network Drives
ECHO 9. Exit this application
ECHO 0. Log Off Windows
ECHO --------------------
 
set choice=
set /p choice=Type the number to start the requested function.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='0' goto logoff
if '%choice%'=='1' goto policy
if '%choice%'=='2' goto smart 
if '%choice%'=='3' goto delfiles
if '%choice%'=='4' goto outlook
if '%choice%'=='5' goto word
if '%choice%'=='6' goto remote
if '%choice%'=='7' goto username
if '%choice%'=='8' goto networkdrives
if '%choice%'=='9' goto end
if '%choice%'=='A' goto start1
 
ECHO "%choice%" is not valid option please try again.
ECHO.
goto start1
 
 
:delfiles
cd \
cd C:\documents and settings\%username%\Local Settings
rd tempor~1 /s/q
echo done
pause
cls
goto start1
 
:policy
cd \
cd C:\Program Files\First Reference\Human Resources PolicyPro Alberta Edition
start PolicyPro2_net.exe
cls
cls
cls
goto start1
 
goto start1
 
:smart
cd \
cd D:\Apps\SmartDraw 7
start SmartDraw.exe
cls
echo done
pause
 
:word
cd \
cd C:\Program Files\Microsoft Office\OFFICE11
start WINWORD.EXE
cls
cls
goto start1
 
:notavail
cls
echo this feature is not available yet, Please try again later
pause
cls
goto start1
 
 
:outlook
cd /
cd "C:\Program Files\Microsoft Office\OFFICE11
start OUTLOOK.EXE
cls
cls
goto start1
 
:remote
cd /
cd C:\Program Files\LogMeIn Rescue Calling Card
start CallingCard.exe
cls
cls
goto start1
 
:username
cls
cls
goto start
goto start1
 
:sys1
cls
systeminfo /s fcs001
pause
cls
goto start1
 
 
:networkdrives
echo Deleting old drives
net use * /delete /y
echo done
echo mapping I drive to Applications
net use I: \\fcs001\apps
echo done
echo mapping N drive to Data
net use N: \\fcs001\data
echo done
echo mapping P drive to Database
net use P: \\fcs001\database
echo done
cls
cls
goto start1
 
:logoffyes
logoff

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:

Select allOpen in new window

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...