• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4830
  • Last Modified:

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

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
bstillion
Asked:
bstillion
  • 5
  • 2
1 Solution
 
RobSampsonCommented:
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
 
MarkThomasLeeCommented:
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
 
bstillionAuthor Commented:
I adapting your suggestion Rob. I'll know by the end of the day and will respond back.

Brad
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
bstillionAuthor Commented:
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
 
bstillionAuthor Commented:
Your VBScripts are great and get me motivated to learn more.
Thanks!

Brad
0
 
bstillionAuthor Commented:
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
 
RobSampsonCommented:
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
 
bstillionAuthor Commented:
...It maintains the default printer too!

Brad
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now