How to use 2 variables on a batch file?

November 7, 2010 at 18:22:57
Specs: Windows XP
I'm trying to name and assigned printer ports with the FOR command in DOS, here is what I have:

REM Add Printer to the corresponding port
FOR %t IN (01,02) DO cscript prnmngr.vbs -a -p "DELL%t" -m "Dell Color Laser 5110cn PCL6" -r IP_135.218.135.%c

I would like to create a set for the 2nd variable (%c), how can I achieve this in the FOR command, or maybe is there a way to create a global variable set.

Thanks in advanced!

CT


See More: How to use 2 variables on a batch file?

Report •

#1
November 8, 2010 at 03:18:17
What you want to achieve is not clear and needs to be better explained.

Anyway pay attention in a batch script the internal variables must be prefixed by a pair of %, i.e. %%t and %%c. Maybe you want to use an environmental variable, e.g. %var%, that is defined by a SET statement (set var=something).


Report •

#2
November 8, 2010 at 05:01:35
Thank you IVO,

What I'm trying to achieve is create a script to install 4 to 5 printers, this is what I have so far:

REM @ECHO OFF

CD %windir%\system32\


REM Add the TCP/IP Ports
FOR %%s IN (6,7) DO cscript prnport.vbs -a -r IP_135.218.135.%%s -h 135.218.135.%%s -o raw -n 9100 -me -y public -i 1

REM Install the Dell 5110cn Printer Driver
cscript prndrvr.vbs -a -m "Dell Color Laser 5110cn PCL6" -i c:\dell\drivers\5110cn-a04\Win_x32\PCL\English\dlxzizi.inf -h c:\dell\drivers\5110cn-a04\Win_x32\PCL\English

REM Add Printer to the corresponding port THIS WHERE I GET STUCK!
FOR %%c IN (6,7) DO (FOR %%t IN (01,02) DO cscript prnmngr.vbs -a -p "DELL%%t" -m "Dell Color Laser 5110cn PCL6" -r IP_135.218.135.%%c)

In the last instruction, I'm trying to use 2 variables, one for the naming of the printer and the other one for the port.So it will name them like this:

DELL01 with port 135.218.135.6
DELL02 with port 135.218.135.7

The last instruction names the printers, but assigns both to the first port only, I'm really close but I'm stuck. I'll appreciate your help.


Report •

#3
November 8, 2010 at 05:50:26
If the port numbers are in sequence the following does the job

REM Add Printer to the corresponding port
setlocal EnableDelayedExpansion
set port=6
FOR %%t IN (01,02) DO (
  cscript prnmngr.vbs -a -p "DELL%%t" -m "Dell Color Laser 5110cn PCL6" -r IP_135.218.135.!port!
  set /A port+=1
)

The SETLOCAL statement enables the "delayed expansion" of environment variables that now behave as dynamic objects and are marked by ! instead of the usual %. To know more type SET /? at prompt. By the way this is NT batch scripting NOT DOS.

Report •

Related Solutions

#4
November 8, 2010 at 06:30:00

Thank you IVO! I stand corrected is NT Batch scripting. Not bad for a newbie like me. Thanks again!

Report •

Ask Question