Batch File Help; entering variables

Joined
Jan 14, 2002
Messages
856
copy \\<servervariable>\VPHOME\GRC.DAT \\<desktopvariable>\C$\Documents and Settings\All Users\Application Data\Symantec\Norton AntiVirus Corporate Edition\7.5\

This is all I have so far. I know very little about batch files, just enough to get by, but as far as entering variables, I don't know how to do that at all. I want to run the batch file, have it ask me for a server name, then a destination computer name and then run the copy.

TIA.
 
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q77457&

The MS-DOS batch language facility does not provide a means for you to provide input to control program flow. All information input from you must be entered from the command line.

By using a short program created with the MS-DOS Debug utility, you can provide information at the time of batch file execution.

NOTE: Although the Debug program works with MS-DOS 6.0 or 6.2, it is not required. If you are using MS-DOS 6.0 or 6.2, type help choice at the MS-DOS command prompt for more information.

Variables from the command line are %1%, %2% etc. %0% is the name of the batch file (actually the name of the command on the command line, so entering 'test' instead of 'test.bat' would set %0% to 'test'.)
 
Are you really using MS-DOS, ButWeizErr? I thought it was dead. If you're actually using Windows, you're in much better shape: the Windows command interpreter, CMD.EXE, supports prompting for environment variables.

This batch file:

Code:
SET /P Response="Please type something:   "
ECHO You typed: %Response%

looks like this when run:

Code:
C:\Documents and Settings\mikeblas>foo

C:\Documents and Settings\mikeblas>SET /P Response="Please type something:  "
Please type something:  something

C:\Documents and Settings\mikeblas>ECHO You typed: something
You typed: something
C:\Documents and Settings\mikeblas>


You can add a line that says "@ECHO OFF" to the batch to get rid of the command echoes from the script.
 
Also, don't forget to put those paths in quotes since they have spaces in them.
 
This seems to work:

##############

@echo off
echo Enter Server Name:
set /p sname=

echo Enter Workstation Name:
set /p wname=

copy \\%sname%\VPHOME\GRC.DAT \\%wname%\C$\docume~1\alluse~1\applic~1\symantec\norton~1\7.5

##############

Any potential issues with this? I did notice i had a wname and sname entry when I run 'set' from the command prompt, but they appear to be gone now. Does/Did that mean anything?

Thanks for your help guys, appreciated.
 
BuudWeizErr said:
Any potential issues with this?
Yeah: you've used the short file name for the target machine. How do you know it's correct? SFNs are generated from LFNs, and a collision might make the SFN different than what you expect.

You might have to put everything in quotes, as korpse pointed out.
 
BuudWeizErr said:
This seems to work:
I did notice i had a wname and sname entry when I run 'set' from the command prompt, but they appear to be gone now. Does/Did that mean anything?
Don't worry about that - As soon as you close the command window the variables are destroyed. However if you want them to only last for the duration of the batch file put the line "setlocal" on the top of your batch file and "endlocal" at the bottom (no quotes).
 
Back
Top