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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to install printers from CSV?

Status
Not open for further replies.

XRJoe

MIS
Feb 27, 2004
76
US
I have roughly 760 printers that need to be installed where Print Migrator failed. A coworkers found a script that was used in the past to install printers via a csv file. It's been a while since I used any VB but the syntax looks all wrong to me...

The CMD file:
cscript /nologo “C:\Program Files\Windows Resource Kits\tools\portmgr.vbs" -a -c \\APRINTERS -p IP_%%b -h %%b -t raw -n 9100"

rundll32 printui.dll,PrintUIEntry /if /b “%%a" /c\\APRINTERS /u /f “%%d” /r IP_%%b /m “%%c”

rundll32 printui.dll,PrintUIEntry /Xs /n\\APRINTERS\%%a Sharename %%a

The CSV file contains: PrinterName, IPAddres, DriverName, DriverLocation

And I was running it with:

for /f “tokens=, Delims=*” %a in (FILE.CSV) do (FILE.CMD)

However this would return an error "Delims was unexpected at this time."

Anyone have any suggestions for a VBScript n00b? Thanks!
 
Oh and I do have the Windows 2003 resource kit installed, and the \\Aprinters is the print server cluster name.
 
There are several issues with the FOR line and the cmd file that you are using. The documentation for the FOR command is obtained by issuing a For /? command.

Delims are the delimiter characters within your data file. If your file is comma delimited, use a comma, etc. Put the proper delimiter and this error should go away.

The tokens field is significant. The data file you have looks like:

PrinterName, IPAddres, DriverName, DriverLocation
2ndfloor_color, 127.0.0.1, color_driver.inf, c:\color

In this example, you have 4 tokens, one for each of the csv fields. Since you want to use all of them they are tokens=1-4.

Next, you have to feed your cmd file the data from your data file. As each line is read, the first field is given the designation %a, the second is %b and so on.

Finally, if you run the FOR command within a batch file, you use the %%x for each of the variables holding the field data. Since you are feeding this output into a cmd file as arguments to that file, the %%x variables wont work. You must change them within the cmd file to %1 for %%a through %4 for %%d.

So, your For command should look like:

for /f “tokens=1-4 Delims=,” %a in (FILE.CSV) do FILE.CMD %a %b %c %d

Testing:
for /f “tokens=1-4 Delims=,” %a in (FILE.CSV) do @echo Printer:%a ip:%b Driver:%c Location:%d

Running this test will debug your data file as well.

Next, test your cmd file which calls the vbscript. Take the output of one line in your data file, and issue (assuming the file is foo.cmd:

foo 2ndfloor_color 127.0.0.1 color_driver.inf c:\color

If your printer is created and your data checks out run:
for /f “tokens=1-4 Delims=,” %a in (FILE.CSV) do FILE.CMD %a %b %c %d

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top