VBScript - check if printer exists; delete old queue; install new queue

Posted on 2011-02-18
Last Modified: 2012-05-11
I will be migrating print queues to a new Windows 2003 Server next week and need a script that will:
Check the network printers currently installed on a PC (enumPrinterConnections)
against a list of print queues that will be moved to the new server
If the PC has a queue that will be moved, delete the current queue and install the new queue
If the PC does not have the queue that will be moved, do nothing and continue to check the next printer (without invoking an error message.) There are 9 queues that will be moved but not all PCs have every queue installed. There is a logon script which is a .bat file but I think a .vbs script can be called from it.

Adding and removing is simple enough:
'Remove a specific printer
WSHNetwork.RemovePrinterConnection PrinterPathDel
'Install A Printer
WSHNetwork.AddWindowsPrinterConnection PrinterPathAdd

but looping through both lists (currently installed and new queues to add)
is a little beyond me. I not sure how to use IF statements in this situation either.
Question by:bstillion
  • 5
  • 2
LVL 65

Accepted Solution

RobSampson earned 500 total points
ID: 34935528
Hi, I have used the script shown here:

to remap printers from one server to another.  The arrPrinterShares array is where you place your oldprintername and your newprintername, and it should map those, and log the results.



Expert Comment

ID: 34935949
I've had pretty good luck using snip its of the code from the following site:
Connecting Drive Letters: 

Connecting, setting defaults and removing printers

Good luck!

Author Comment

ID: 34944836
I adapting your suggestion Rob. I'll know by the end of the day and will respond back.


Author Comment

ID: 34945090
Thanks Rob!
As always, your script is exactly what I needed.

I used the 2nd version without IP Filtering. The log it creates is great for monitoring
what happens and when.
During testing I discovered 7 queues that were duplicated on another server so it
also helped me clean up the newly acquired organization that has not had dedicated
IT support for too long.

Thanks again for your excellent (and fast!) solution!

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.


Author Closing Comment

ID: 34945097
Your VBScripts are great and get me motivated to learn more.


Author Comment

ID: 34945303
In the array with old and new printer queues, I had to identify the
printers by display name rather than share name.
Took me some time to discover that so I wanted to save future users of this script some time.

LVL 65

Expert Comment

ID: 34946600
Hi, thanks for that, I'm glad it helped.  Yeah, I think I noticed that it was display name after someone else tried it out.  The reason I didn't pick up on it was because we always have the display and share name identical.



Author Comment

ID: 34953794
...It maintains the default printer too!


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is my 3rd article on SCCM in recent weeks, the 1st ( dealing with installat…
Have you considered what group policies are backwards and forwards compatible? Windows Active Directory servers and clients use group policy templates to deploy sets of policies within your domain. But, there is a catch to deploying policies. The…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now