Anyone?
Main Topics
Browse All TopicsPlease look at this batch file, and and modify it so that it can go through the list of printers and their ports (prns.txt & prts.txt) and run through the rest of the script in tandem - meaning that printer1 with port1, printer2 with port2 and so on.
This script works if there is just one printer. Fails when there's 2 or more, which is always the case.
Thank you for your time.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> netcmh
As mentioned, in line 60 the "&" symbols need to be changed to something else, like "and" maybe.
In this section:
:process_files
echo Processing files to extract variables
FOR /F "tokens=1 delims=" %%A in ('type c:\temp\prns.txt') do SET myVar1=%%A
set myvar1=%myvar1:Printer name =%
FOR /F "tokens=1 delims=" %%A in ('type c:\temp\prts.txt') do SET myVar2=%%A
set myvar2=%myvar2:Port name =%
FOR /F "tokens=1 delims=" %%A in ('type c:\temp\defprn.txt') do SET myVar3=%%A
set myvar3=%myvar3:The default printer is =%
exit /b
I suspect that you are trying to worj through each of the printers exported. But each of the FOR loops is going to run independently, and only set the MYVARn to the last line of each file. I think what you want it to pair up the printers and ports and then process each pair somehow. That matching process isn't simple though.
~bp
Hi netcmh
Try this VBS file and see if it provides you with some helpful comma-separated information when run. Save it as something like "PrinterPorts.vbs" and call it using:
cscript printerports.vbs
or
cscript printerports.vbs > report.txt
The header line that is echoed first can be eliminated by deleting the section:
WScript.Echo "Device_ID" & "," _
& "Port_Name" & "," _
& "Is_Default"
I just put it there so you can see what each field is.
There are two other printer-related settings that can be retrieved using the WMI "Win32_Printer" Class that seem to report the printer name in addition to "DeviceID". It would be worth comparing the results by substituting the line:
WScript.Echo objItem.DeviceID & "," _
for
WScript.Echo objItem.Caption & "," _
and
WScript.Echo objItem.Name & "," _
Note: The _ at the end of the lines just allows the line to be carried over onto a new line in the code without affecting the functionality of the command.
The & "," is just creating a comma without any leading or trailing spaces between the fields. The intention here is to get your Printer Name and Port name onto one line. Delete the
& objItem.Default
line and the & "," _ on the line above it to just output Printer Name and Port Name as two comma-separated fields.
The intention with this code is to get those two text strings as variables by parsing with the FOR command using "delims=," and using the information. As Bill Prew has stated above though, your current FOR commands are just capturing the last lines of each multi-line text file. Perhaps this VBS file will create a better starting point that can be built on to file away separate variables with each pass.
You can retrieve a whole lot of other Printer-related settings or values with the "Win32_Printer" Class, such as objItem.Status but that's not really relevant.
Give the VBS file a try and see what results you get.
Bill
Try running the VBS file with the following batch file from the same folder as the VBS file. Name the batch file whatever you want to, eg. "Get_Printer_Name-Port.cmd
It will output "report.txt" to the same folder.
I don't like the : at the end of some Port Names, but I believe we can get rid of them by later testing to see if the last character of the string in the variable is a : and stripping it out if true. This is just (hopefully) a step towards getting you a functional batch file.
>> netcmh:
>> Bill,
>> That's exactly what I want. Please point me in the right direction.
>> I'll edit the &
I see that there are now some vbscript things posted, let me know if you are switching over to that approach or wanting to stick with the windows batch approach. I just don't want to spend time trying to work up something in batch if you are going down the vbscript approach.
~bp
BillDL: could you modify that vbs to not show me anything that starts with Microsoft?
Billprew: I would still very much like to keep this in one language and since I consider myself old school, I'd like it all to be in batch file.
BillDL: Would it be possible to create that vbs from the batch file, with something like
echo On Error Resume Next > printerport.vbs
echo . >> printerport.vbs
echo strComputer = "." >> printerport.vbs
Yes, I agree. Sorry for that Bill. I didn't mean to interrupt and divert the flow. I hadn't seen netcmh's follow-up comment because I was testing to see whether there might present a better alternative than using 3 steps and temp files to filter out the results of "prnmngr.vbs". The vbscript idea was really in furtherence of the last part of own comment which was the last comment saw before absenting myself:
"I think what you want it to pair up the printers and ports and then process each pair somehow".
I don't actually know enough about VBS to totally replace a batch file, so my intention would just have been to call it from a batch file and filter the results.
netcmh
No harm in just seeing the output of my suggestion, but as Bill Prew has asked, please let him know if the alternative VBS file seems to give a more viable option before he spends time crafting a new batch file or adapting yours to do the job.
He, he. We're posting out of sync here. This will be my last comment before leaving for the day, but I'll bet the other Bill is typing as I am, so I'm typing fast :-)
Yes, it's possible to create a VBS file on the fly by echoing text strings and redirecting to file with the >> symbol, but there are certain characters that don't like being echoed and need to be prefixed with a ^ to have them treated as literals.
I really need to get to bed now, but will look back in tomorrow morning. I'm on GMT and I'm out on nightshift in 6 hours :-(
You have these inside the "loop" of printers, but shouldn't they really just be executed just one time? There can only be one default printer, right?
echo Deleting exisiting UPD 5.0 driver if exists
Cscript Prndrvr.vbs -d -m "HP Universal Printing PCL 5 (v5.0)" -v 3 -e "Windows NT x86"
echo Installing fresh UPD 5.0 driver from server
rundll32 printui.dll,PrintUIEntry /ia /m "HP Universal Printing PCL 5 (v5.0)" /f "\\server01\upd5pcl5\hpcu0
echo Re-instating the default printer
Cscript Prnmngr.vbs -t -p "%myvar3%"
~bp
Okay, here's what I have. I assumed the answers to my last post were that those two items only needed to be done once.
I have used an environment variable called DEBUG in the script. You will see that I set this to an ECHO command for this testing since I didn't want to actually run some of the code on my system, but wanted to see the statements that would have executed. Run it on your system the way it is, then to actually have it do the command just uncomment out the last SET DEBUG= line.
Once you get it working good we can remove all the DEBUG related stuff.
I'm including the log file from my test run here, seems to be what I expected, but you can better decide.
~bp
Business Accounts
Answer for Membership
by: netcmhPosted on 2009-11-04 at 12:55:00ID: 25743802
Also, line #89
91b.inf" /u
rundll32 printui.dll,PrintUIEntry /ia /m "HP Universal Printing PCL 5 (v5.0)" /f "\\server01\upd5pcl5\hpcu0
would call a program to install a print driver from the server. typing that into the command prompt shows me that the command is executed immediately, but it opens up a GUI download and install. Is there a way to wait untill that GUI vanishes- without using 3rd party apps.