[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2003-11-03
10
Medium Priority
?
711 Views
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.
0
Comment
Question by:studios
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
10 Comments
 
LVL 2

Assisted Solution

by:CCEtech
CCEtech earned 200 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.
0
 
LVL 7

Accepted Solution

by:
Focusyn earned 200 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, Baker.bet 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.

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

SET USRINPUT=

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:
COPY CON %TEMP%.\~USRINP.TMP

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

REM * Add empty line to temporary file. The empty line
REM * will be used to stop DATE asking for new date.
ECHO.>> %TEMP%.\~USRINP.TMP
ECHO.>> %TEMP%.\~USRINP.TMP

REM * Create a temporary batch file that will store the
REM * entered text into the environment variable USRINPUT:
TYPE %TEMP%.\~USRINP.TMP | DATE | FIND "):" > %TEMP%.\~USRINP.BAT

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
ECHO SET USRINPUT=%%3>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:
ECHO SET USRINPUT=%%6>VOER.BAT
ECHO SET USRINPUT=%%4>TYP.BAT

REM * This temporary batch file now sets the variable USRINPUT:
CALL %TEMP%.\~USRINP.BAT

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

REM * Finally, clean up the mess of temporary files:
FOR %%A IN (%TEMP%.\~USRINP.BAT %TEMP%.\~USRINP.TMP VOER.BAT TYP.BAT CURRENT.BAT) DO DEL %%A
0
 

Author Comment

by:studios
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.
0
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
LVL 7

Expert Comment

by:Focusyn
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
0
 
LVL 1

Assisted Solution

by:iaind
iaind earned 200 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 (http://www.tburke.net/info/reskittools/topics/choice.htm)

It would allow you to do something like the following.

Echo Please select one of the following
Echo A - ARNOLD
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 (www.winbatch.com) from WilsonWare.  It is a really powerful scripting language that is so much easier that VBscript
0
 

Author Comment

by:studios
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).
0
 
LVL 1

Expert Comment

by:iaind
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 (www.jpsoft.com), but it would work out more expensive for 15 copies.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Ransomware, the malware that locks down its victim’s files until they pay up, has always been a frustrating issue to deal with. However, a recent mobile ransomware will make the issue a little more personal… by sharing the victim’s mobile browsing h…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 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