Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch parameter 2

Status
Not open for further replies.

asainz

Programmer
May 23, 2002
3
US
I have a batch file that needs a parameter supplied by the end user. In Windows ME I did this by putting

C:\BATCH\CTW2UPLD.BAT ?

in the Cmd line of a shortcut.

This caused an input box to pop up for the user to enter the desired information and then used what ever the user typed as the parameter (%1) in the batch file.

When I tried the same thing in Windows XP, the ? was ignored. There was no input box and no parameter was passed to the batch file.

Does anyone know how to accomplish this in XP?

Any help would be greatly appreciated.
 
InputBox 1.1
11/04/01 Free inpbox11.zip
(191 Kb)
Console mode program that allows you to prompt users for input using a standard Windows input box, then write that input into a file. Makes for a user friendly way of inserting real-time data into batch, registry, INI, or other text files. When you have to ask for input during a batch process, InputBox is what you need.



 
Thanks for your help. It's not quite as convenient as it was in the earlier versions of Windows but it will get the job done.
 
I posted the question on the Microsoft XP forum as well and received this reply:

Assuming you want interactive input, see tip 2545 in the 'NT Reg Hacks' at

Jerold Schulman
Windows Server MVP / Configuration Management
JSI, Inc.

This solution is totally console based. There are no Windows Input Boxes but it is built in to the set command so it doesn't require any extra executables. I thought I would add this to the thread in case anyone else has a similar problem.
 
I know this is an old thread but it solved a problem I just ran into. I needed to prompt a user for the name of a file to transfer via serial port to a CNC machine. It seems to me that I have used the "batch.bat ?" before on win2000 and I'm pretty sure on XP. This time no luck. The set/p command will work fine but does anyone know why XP won't except user input from a command line shortcut?

Thanks asainz for the follow-up posting to the thread. It helped me greatly.
 
Uptime how do you use the set/p cmd, can you give me an example.?

Thanks
 
from "set /?" :
The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty.

so the batch file can read the value of the environment variable as the parameter after the user inputs it. not sure as to exact syntax and usage however.
 
From Jerold Schulman, MVP, site linked earlier:

SET /P variable=[promptString]

"The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty."

Here is a silly little example:
@echo off
setlocal
set OK=N
:again
set /p user=Please enter your User Name or END.
if /i [%user%]==[END] endlocal&goto end
if [%user%]==[] goto again
for /f "Tokens=*" %%i in ('net user "%user%" /domain') do call :parse "%%i"
If "%OK%"=="N" goto again
set /p xxx=Press any key to exit.
endlocal
goto end
:parse
set ustr=%1
if not "%ustr:~1,9%"=="Full Name" goto end
set ustr=%ustr:"=%
set ustr=%ustr:Full Name =%
@echo Thank you %ustr%
set OK=Y
:end



 
Stunpals,

I think jimp56 and bcastner have answered your question. What a great resource Tek-tips is.

Here's a simple example of how I was using the set/p command:

@echo off
setlocal
:getname
set /p tape=Enter tape name or END to exit.
if /i [%tape%]==[END] endlocal&goto end
if [%tape%]==[] goto getname
if exist c:\store\tapes\%tape% goto send
echo Tape %tape% does not exist. Try again.
goto getname
:send
echo The tape c:\store\tapes\%tape% will be sent
Pause
:end
echo exit
pause

I hope this helps you with your application. Good luck.
 
Thanks for the examples, I have created one here that seems to be doing what I want now..

What is the "setlocal" cmd doing and why should it be used..??
Also the first "if" has the "/i" in it but the next 2 don't.?
 
Stunpals,

Glad I could help.

As far as your questions:

the set/p command is setting an environment variable. The setlocal command makes that variable temporary and is cleared after your batch file closes.

The /i command on the if statement makes the command ignore the case of the variable input (i.e. end=END=eNd etc).
 
This is only related as it is the same batch file I have the above comments in.

I have a question regarding the Net Use cmd. Normally I will assign a drive letter or lpt to this cmd. I was talking with a guy that does the following

Net Use \\ComputerName

He doesn't specify a drive.? If you then Run the Net Use you get the Status as OK, No drive letter and the Remote path.
Is there a reason to do this or any advantages. What would be the difference from this method and just using Start->Run->\\ComputerName

What I'm trying to do is create a quick batch file for staff while they are out of the office so they can connect to another office computer that is hosting all the data files without having to logon locally as the same user on both computers and use pass-through authentication. eg C:\DATA\

As well some of our users like to use the My Briefcase for syncing with our server then while out of the office share a folder from within My Briefcase. Since you can not map directly to the Briefcase I was wondering if the Start->Run or the open Net Use \\ComputerName would be best.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top