Question

Batch file - Please look

Asked by: netcmh

Please 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.

::===================================================
:: Automated Printer Driver Change
::
:: This batch file was written by NetCMH
::
:: Version 1.0 for Windows XP
::
:: Script to:
:: 1. Enumerate the printers on the computer
:: 2. List the default printer
:: 3. Delete and re-add printers with UPD 5.0 driver
:: 4. Re-establish the default printer
::=================================================== 
@echo off
setLocal EnableDelayedExpansion 
ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto ver_2003 
ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp 
ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto ver_2000 
ver | find "NT" > nul
if %ERRORLEVEL% == 0 goto ver_nt 
echo Machine undetermined.
goto exit 
:ver_2003
echo Windows 2003
call :create_temp
call :list_printers
call :list_default_printer
call :process_files
rem call :rename_old_files
call :change_drivers
call :cleanup
goto :eof 
:ver_xp
echo Windows XP
call :create_temp
call :list_printers
call :list_default_printer
call :process_files
rem call :rename_old_files
call :change_drivers
call :cleanup
goto :eof 
:ver_2000
echo Windows 2000: Not supported in this version
goto :eof 
:ver_nt
echo Windows NT: Not supported in this version
goto :eof 
:create_temp
if exist "C:\temp\" (
echo. Folder Exists
) else (
mkdir c:\temp\
)
exit /b 
:list_printers
echo Listing printers & ports to text files : c:\temp\prns.txt & c:\temp\prts.txt
cscript //nologo %SYSTEMROOT%\SYSTEM32\prnmngr.vbs -l | findstr /c:"Printer name" | findstr /v "Microsoft" >>  
c:\temp\prns.txt
cscript //nologo %SYSTEMROOT%\SYSTEM32\prnmngr.vbs -l | findstr /c:"Port name" | findstr /v "Microsoft" >> c:\temp\prts.txt
exit /b 
:list_default_printer
echo Listing default printer to text file : c:\temp\defprn.txt
cscript //nologo %SYSTEMROOT%\SYSTEM32\prnmngr.vbs -g >> c:\temp\defprn.txt
exit /b 
: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 
:rename_old_files
ren C:\WINDOWS\system32\spool\drivers\w32x86\3\HPBMINI.dll C:\WINDOWS\system32\spool\drivers\w32x86\3\OLD_HPBMINI.dll
ren C:\WINDOWS\system32\spool\drivers\w32x86\3\HPCDMC32.dll C:\WINDOWS\system32\spool\drivers\w32x86\3\OLD_HPCDMC32.dll
exit /b 
:change_drivers
echo Changing Drivers:
for /f "tokens=* delims= " %%a in (c:\temp\prns.txt) do (
cd %SystemRoot%\system32
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\hpcu091b.inf" /u
echo Deleting printers
Cscript Prnmngr.vbs -d -p "%myvar1%"
echo Adding printers
cscript prnmngr.vbs -ac -p "%myvar1%" -m "HP Universal Printing PCL 5 (v5.0)" -r "%myvar2%"
echo Re-instating the default printer
Cscript Prnmngr.vbs -t -p "%myvar3%"
if errorlevel 1 (echo %%a >> c:\temp\failed.txt
) else (
echo Success
)
) 
:cleanup
echo Cleaning up
echo y|del c:\temp\prns.txt
echo y|del c:\temp\prts.txt
echo y|del c:\temp\defprn.txt 
:eof
exit

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-04 at 12:46:40ID24872406
Tags

DOS batch

Topics

MS DOS

,

Windows Batch Scripting

,

Automation

Participating Experts
3
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Batch Script
    What is the easiest way to search for windows 2000 or XP in batch and run a command if 2K exists and if XP exists run a differerent command. Finally I wont to dump the output to text. This will run the logon scripts. If I can have veryone's result dump to the same text file...
  2. BATCH FILE
    Hi Does anyone know how to fire a PHP script using a BATCH file? Thanks
  3. Batch File
    Hi... I'm trying to create a batch file that is supposed to check a directory for specific file extensions and then delete them or move them to a different folder. After that it is supposed to send a message to the administrator or send an email to the administrator. Is t...
  4. batch script
    How dow I delete all printers from Windows XP PRO/ WIN2K PRO? I would like to set in the log in script that it will delete all the printers. After that how do I add printers via batch script. i.e. \\server1\share\printer.bat
  5. batch script to delete all printers
    is there a batch script that could delete all added printers without having to know each printers name ?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: netcmhPosted on 2009-11-04 at 12:55:00ID: 25743802

Also, line #89

rundll32 printui.dll,PrintUIEntry /ia /m "HP Universal Printing PCL 5 (v5.0)" /f "\\server01\upd5pcl5\hpcu091b.inf" /u

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.

 

by: netcmhPosted on 2009-11-04 at 13:53:04ID: 25744361

Anyone?

 

by: TheNauticanPosted on 2009-11-04 at 16:22:23ID: 25745655

netcmh, are running this in pure dos? Im trying this in XP and getting errors with the &. I escape them with a ^ then get some other errors.

 

by: billprewPosted on 2009-11-04 at 17:26:30ID: 25745972

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

 

by: netcmhPosted on 2009-11-05 at 05:54:14ID: 25749413

Bill,

That's exactly what I want. Please point me in the right direction.

I'll edit the &

 

by: BillDLPosted on 2009-11-05 at 07:18:51ID: 25750358

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

On Error Resume Next
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
 
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer")
 
WScript.Echo "Device_ID" & "," _
    & "Port_Name" & "," _
    & "Is_Default"
 
For Each objItem In colItems
    WScript.Echo objItem.DeviceID & "," _
        & objItem.PortName & "," _
        & objItem.Default
 
    'WScript.Echo
Next

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:

Select allOpen in new window

 

by: BillDLPosted on 2009-11-05 at 07:34:04ID: 25750543

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.

@echo off
 
if exist "%CD%\report.txt" del "%CD%\report.txt" > nul
 
for /f "skip=2 tokens=1,2 delims=," %%a in ('cscript printerports.vbs ^| find /i /v "Microsoft"') do @echo %%a,%%b>> report.txt
 
pause
exit

                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: billprewPosted on 2009-11-05 at 07:52:31ID: 25750762

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

 

by: BillDLPosted on 2009-11-05 at 07:57:16ID: 25750802

Sorry, I was forgetting the cscript //nologo option.  If used, the "skip=2" is not required.  That just tells it to disregard the first 2 lines of the output which, if cscript is used without //nologo, is the header detail of the program.

 

by: netcmhPosted on 2009-11-05 at 08:03:04ID: 25750862

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


 

by: netcmhPosted on 2009-11-05 at 08:08:22ID: 25750919

cscript //nologo c:\temp\printerport.vbs | findstr /v "Microsoft" > output.txt

 

by: BillDLPosted on 2009-11-05 at 08:08:25ID: 25750920

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.

 

by: BillDLPosted on 2009-11-05 at 08:13:01ID: 25750965

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 :-(

 

by: netcmhPosted on 2009-11-05 at 08:13:52ID: 25750976

Thanks & Good night

 

by: billprewPosted on 2009-11-05 at 17:14:09ID: 25755910

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\hpcu091b.inf" /u

 echo Re-instating the default printer
 Cscript Prnmngr.vbs -t -p "%myvar3%"

~bp

 

by: billprewPosted on 2009-11-05 at 18:55:26ID: 25756271

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

::===================================================
:: Automated Printer Driver Change
::
:: This batch file was written by NetCMH
::
:: Version 1.0 for Windows XP
::
:: Script to:
:: 1. Enumerate the printers on the computer
:: 2. List the default printer
:: 3. Delete and re-add printers with UPD 5.0 driver
:: 4. Re-establish the default printer
::===================================================
@echo off
setLocal EnableDelayedExpansion
 
set DEBUG=echo.*DEBUG*_
set DEBUG=%DEBUG:_= %
set DEBUG=
 
call :get_windows_version
goto :ver_%WinVer%
 
:ver_2003
:ver_xp
  echo Windows XP
  call :create_temp
  call :list_printers
  call :list_default_printer
  call :rename_old_files
  call :change_drivers
  call :cleanup
  exit /b
 
:ver_2000
  echo Windows 2000: Not supported in this version
  exit /b
 
:ver_nt
  echo Windows NT: Not supported in this version
  exit /b
 
:ver_none
  echo Windows version not determined
  exit /b
 
:get_windows_version
  set WinVer=none
  ver | find "2003" > nul
  if %ERRORLEVEL% == 0 (
    set WinVer=2003
    exit /b
  )
  ver | find "XP" > nul
  if %ERRORLEVEL% == 0 (
    set WinVer=xp
    exit /b
  )
  ver | find "2000" > nul
  if %ERRORLEVEL% == 0 (
    set WinVer=2000
    exit /b
  )
  ver | find "NT" > nul
  if %ERRORLEVEL% == 0 (
    set WinVer=nt
    exit /b
  )
  exit /b
 
:create_temp
  if not exist "c:\temp\" mkdir "c:\temp"
  exit /b
 
:list_printers
  echo Listing printers and ports to text files: c:\temp\prns.txt, c:\temp\prts.txt
  cscript //nologo %SYSTEMROOT%\SYSTEM32\prnmngr.vbs -l | findstr /c:"Printer name" | findstr /v "Microsoft">>c:\temp\prns.txt
  cscript //nologo %SYSTEMROOT%\SYSTEM32\prnmngr.vbs -l | findstr /c:"Port name" | findstr /v "Microsoft">>c:\temp\prts.txt
  exit /b
 
:list_default_printer
  echo Listing default printer to text file : c:\temp\defprn.txt
  cscript //nologo %SYSTEMROOT%\SYSTEM32\prnmngr.vbs -g>>c:\temp\defprn.txt
  exit /b
 
:rename_old_files
  %DEBUG%ren C:\WINDOWS\system32\spool\drivers\w32x86\3\HPBMINI.dll C:\WINDOWS\system32\spool\drivers\w32x86\3\OLD_HPBMINI.dll
  %DEBUG%ren C:\WINDOWS\system32\spool\drivers\w32x86\3\HPCDMC32.dll C:\WINDOWS\system32\spool\drivers\w32x86\3\OLD_HPCDMC32.dll
  exit /b
 
:change_drivers
  echo Changing Drivers:
  cd %SystemRoot%\system32
  echo Deleting exisiting UPD 5.0 driver if exists
  %DEBUG%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
  %DEBUG%rundll32 printui.dll,PrintUIEntry /ia /m "HP Universal Printing PCL 5 (v5.0)" /f "\\server01\upd5pcl5\hpcu091b.inf" /u
 
  set /a i=0
  for /F "tokens=* delims=" %%A in ('type c:\temp\prns.txt') do (
    set /a i+=1
    set myVar1=%%A
    set myvar1=!myvar1:Printer name =!
    set /a j=0
    for /F "tokens=* delims=" %%B in ('type c:\temp\prts.txt') do (
      set /a j+=1
      if !i!==!j! (
        set myVar2=%%B
        set myvar2=!myvar2:Port name =!
        echo Deleting printers
        %DEBUG%Cscript Prnmngr.vbs -d -p "!myvar1!"
        echo Adding printers
        %DEBUG%cscript prnmngr.vbs -ac -p "!myvar1!" -m "HP Universal Printing PCL 5 (v5.0)" -r "!myvar2!"
      )
    )
  )
 
  echo Re-instating the default printer
  for /F "tokens=* delims=" %%C in ('type c:\temp\defprn.txt') do (
    set myvar3=%%C
    set myvar3=!myvar3:The default printer is =!
  )
  %DEBUG%Cscript Prnmngr.vbs -t -p "%myvar3%"
  exit /b
 
:cleanup
  echo Cleaning up
  %DEBUG%if exist c:\temp\prns.txt del c:\temp\prns.txt
  %DEBUG%if exist c:\temp\prts.txt del c:\temp\prts.txt
  %DEBUG%if exist c:\temp\defprn.txt del c:\temp\defprn.txt
  exit /b
 
 
===== OUTPUT LOG FILE =====
Windows XP
Listing printers and ports to text files: c:\temp\prns.txt, c:\temp\prts.txt
Listing default printer to text file : c:\temp\defprn.txt
*DEBUG* ren C:\WINDOWS\system32\spool\drivers\w32x86\3\HPBMINI.dll C:\WINDOWS\system32\spool\drivers\w32x86\3\OLD_HPBMINI.dll
*DEBUG* ren C:\WINDOWS\system32\spool\drivers\w32x86\3\HPCDMC32.dll C:\WINDOWS\system32\spool\drivers\w32x86\3\OLD_HPCDMC32.dll
Changing Drivers:
Deleting exisiting UPD 5.0 driver if exists
*DEBUG* Cscript Prndrvr.vbs -d -m "HP Universal Printing PCL 5 (v5.0)" -v 3 -e "Windows NT x86"
Installing fresh UPD 5.0 driver from server
*DEBUG* rundll32 printui.dll,PrintUIEntry /ia /m "HP Universal Printing PCL 5 (v5.0)" /f "\\server01\upd5pcl5\hpcu091b.inf" /u
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "Text"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "Text" -m "HP Universal Printing PCL 5 (v5.0)" -r "FILE:"
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "Send To OneNote 2007"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "Send To OneNote 2007" -m "HP Universal Printing PCL 5 (v5.0)" -r "XPSPort:"
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "MFP"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "MFP" -m "HP Universal Printing PCL 5 (v5.0)" -r "IP_192.168.59.132"
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "Duplex"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "Duplex" -m "HP Universal Printing PCL 5 (v5.0)" -r "IP_192.168.59.86"
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "Color"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "Color" -m "HP Universal Printing PCL 5 (v5.0)" -r "IP_192.168.59.85"
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "Adobe PDF"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "Adobe PDF" -m "HP Universal Printing PCL 5 (v5.0)" -r "My Documents\*.pdf"
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "\\pvdres02\PVDRCH03LZ02"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "\\pvdres02\PVDRCH03LZ02" -m "HP Universal Printing PCL 5 (v5.0)" -r "IP_192.168.59.132"
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "\\pvdres02\RCH03-LZR-01"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "\\pvdres02\RCH03-LZR-01" -m "HP Universal Printing PCL 5 (v5.0)" -r "IP_192.168.59.86"
Deleting printers
*DEBUG* Cscript Prnmngr.vbs -d -p "\\pvdres02\RCH03-LZR-02"
Adding printers
*DEBUG* cscript prnmngr.vbs -ac -p "\\pvdres02\RCH03-LZR-02" -m "HP Universal Printing PCL 5 (v5.0)" -r "IP_192.168.59.85"
Re-instating the default printer
*DEBUG* Cscript Prnmngr.vbs -t -p "MFP"
Cleaning up

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:

Select allOpen in new window

 

by: netcmhPosted on 2009-11-09 at 11:15:48ID: 31650210

Thank you.

 

by: BillDLPosted on 2009-11-10 at 12:42:12ID: 25789596

Thank you netcmh.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...