Solved

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

Posted on 2011-02-18
8
4,726 Views
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.
0
Comment
Question by:bstillion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 34935528
Hi, I have used the script shown here:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_22955704.html

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.

Regards,

Rob.
0
 
LVL 1

Expert Comment

by:MarkThomasLee
ID: 34935949
I've had pretty good luck using snip its of the code from the following site:
Connecting Drive Letters:
http://computerperformance.co.uk/Logon/Logon_HomeDirAdv.htm 

Connecting, setting defaults and removing printers
http://computerperformance.co.uk/Logon/LogonScript_Printer.htm

Good luck!
m
0
 

Author Comment

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

Brad
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:bstillion
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!

Brad
0
 

Author Closing Comment

by:bstillion
ID: 34945097
Your VBScripts are great and get me motivated to learn more.
Thanks!

Brad
0
 

Author Comment

by:bstillion
ID: 34945303
Note:
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.

Brad
0
 
LVL 65

Expert Comment

by:RobSampson
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.

Regards,

Rob.
0
 

Author Comment

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

Brad
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 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