Need to pass a user-supplied parameter to a batch file from a desktop shortcut.

When a user clicks on an icon that represents a batch file, I'd like to prompt them for a parameter, which is then passed in to a batch file.  

I'm able to do this in Windows 98.  I create a shortcut to the batch file, and then put a question mark after the name of the batch file in the CMD Line field, ie:

C:\GPS\GPS.bat   ?

When the user clicks on the icon for this shortcut, they are prompted to type in a value, which the batch file uses.  In this specific case, it is Great Plains Accounting, and the user is selecting which company to open.

( If they were at a DOS prompt, they could type   GPS ARNOLD  or GPS BAKER and Great Plains would open the ARNOLD or BAKER company directories. This is what I'm trying to replicate.)

I went to do this on Windows 2000, and it doesn't work.  As we're migrating the users from Win98 to Win2000, I need to bring the old functionality forward.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have you thought about using vbscript to send the parameters to the batch file? You could create an input box so a user can type in ARNOLD or BAKER to get the directories.
You can do it with variable commands in the batch file using the %0-%9 commands.  This will not prompt the user, but will enable the variable to be entered at the command line or hard coded in to the shortcut.  For Example:

I"m not sure which operation you are executing on the directories in question, but we'll use xcopy for an example.  If there are multiple directories, called Baker and Arnold, and you want to copy the files contained in the specified directory on a network drive mapped as X:\ to the user's C drive,  you can use the syntax;

at the command line you would type
GPS Arnold

and the batch file would look like this

xcopy x:\%1 c:\

the result would be xcopy x:\Arnold c:\

you can use the %0-%9 variables with any operation in the batch file.  

To do actual user prompted when a batch file is run is much more difficult, and probably not worth the trouble in this case, since I"m assuming you are going to be working within the same group of a few different choices.  I might suggest even that if the directory lists are not changing, the easier way would be to create batch files with the names already in them and name them Arnold.bat, etc.  Create them on a network drive and copy them down, or even make shortcuts to them, on the users' desktops, so that you are creating the shortcuts only once, and skip the vriables altogether.  

The following is an example of asking for user input within a batch file from Rob van der Woude's Scripting tutorial pages that stores it in a temporary text file, then calls that text file to read the variable from it, which is the quickest way I can find of usnig variable strings from user prompts.  The REM'd lines explain what is giong on throughout the example.

REM * Ask for USeR INPUT and store it in variable USRINPUT
REM * Written by Rob van der Woude


REM * Turn on ANSI key translation (translate Enter
REM * key to F6+Enter sequence) and ask for input:
ECHO Enter one word only . . .

REM * Copy entered text to temporary file:

REM * Turn off ANSI key translation and clear irrelevant screen output:

REM * Add empty line to temporary file. The empty line
REM * will be used to stop DATE asking for new date.

REM * Create a temporary batch file that will store the
REM * entered text into the environment variable USRINPUT:

REM * Create more temporary batch files. Add
REM * more command line parameters if necessary,
REM * as in: ECHO SET USRINPUT=%%3 %%4 %%5 %%6 %%7 %%8 %%9>CURRENT.BAT

REM * VOER.BAT and TYP.BAT are replacements for CURRENT.BAT for Dutch
REM * DOS versions; add your own language versions if necessary:

REM * This temporary batch file now sets the variable USRINPUT:

REM * Display the result:
ECHO You typed: %USRINPUT%

REM * Finally, clean up the mess of temporary files:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
studiosAuthor Commented:
The batch file all ready uses %1 to accept the company name.

I'm trying to prompt the user for the value to pass in.

Since I posted, I've learned that I have to use the 16-bit MS-DOS prompt instead of the 32-bit MS-DOS prompt.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

unless I misunderstand what you are trying to do, you can use %2 for the next value.  Like the batch file would be
[operation] %1 %2
where the user types at the command line
GPS [company name] [value]

and it will plug the values in in order starting with 1
One option would be the use of CHOICE.  I think that it comes with the 2000 Resource Kit (I know that it came with the NT4 resource Kit).  Here is a link that explains it in more detail and some links (

It would allow you to do something like the following.

Echo Please select one of the following
Echo B - BAKER
Choice /c:AB Push the Key of your selection
If ErrorLevel 2 goto :Arnold
If ErrorLevel 1 goto :Baker

A book you might want to look at is "Windows NT Shell Scripting! by Tim Hill.  ISBN - 1-57870-04707.

Or as CCEtech above mentioned look at a scripting language.  My personal preference would be for Winbatch ( from WilsonWare.  It is a really powerful scripting language that is so much easier that VBscript
studiosAuthor Commented:
The 16-bit COMMAND version does take a question mark and put a window-panel up that querries the user for an input, which then goes to the %1 position in the batch file.  

The choice option looks interesting, except that there are about 50 possible choices, and it would be high-maintenance to be changing the batch file, plus the 50 names would scroll off most screens.

The big batch file is quite a piece of work, and would require some more work to work in the multi-user environment, since I've got about 12 users starting up this process all during the day.  I've looked at WinBatch before, and think it is a great product, but I think I'd have to license about 15 copies, and haven't taken that up with the client.  

So, I'll stay with the in-elegant, but function 16-bit COMMAND environment (instead of the 32-bit CMD environment).
ok.  winbatch does have an option where you can 'compile' the scripts into exe's so that they can run on PC's without Winbatch.  It is more expensive but if you work with a number of clients it can be extreamly powerful. The Compiler costs ~$500 and then you can run the compliled code on as many computers as you wish.  I have been using Winbatch for over 6 years and mush say that Wilson Ware support is second to none.

Another option could be 4NT from JPSoftware (, but it would work out more expensive for 15 copies.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.