Link to home
Start Free TrialLog in
Avatar of martinpyt
martinpyt

asked on

DOS batch file with user input variable

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
Avatar of dreffed
dreffed
Flag of Canada image

Hi Martin

Are you using Windows NT?
otherwise you could try this link
http://www.roanoke.infi.net/~wtnewton/batch/batchfaq.html#12
Avatar of dbrunton
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
Avatar of vinnyd79
vinnyd79

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
ASKER CERTIFIED SOLUTION
Avatar of rin1010
rin1010

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of martinpyt

ASKER

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
I tested the suggestion - the usrprmpt.bat ? was exactly what I needed. Thanks!
how to get yesterday's date dynamically in a batch program.


Thanks
Mahi
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

Open in new window