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

Posted on 2003-11-03
Last Modified: 2010-08-05
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.
Question by:studios
  • 2
  • 2
  • 2
  • +1

Assisted Solution

CCEtech earned 50 total points
ID: 9672982
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.

Accepted Solution

Focusyn earned 50 total points
ID: 9673324
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:

Author Comment

ID: 9673446
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.
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.


Expert Comment

ID: 9673477
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

Assisted Solution

iaind earned 50 total points
ID: 9673658
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

Author Comment

ID: 9676775
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).

Expert Comment

ID: 9677129
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.

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 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