Solved

Modify printer logon script to check if printers already exist

Posted on 2010-11-19
4
802 Views
Last Modified: 2012-05-10
hello everyone,

We are using the below code as a logon script to connect everyone to their printers.  All the printers are hosted on the same Server 2003 machine.

Recently, we decided to cut down on the time spent installing each printer every single time the user logs on.  Specifically, we'd like to modify our script to check if each printer, in turn, already exists on the workstation, and skip that printer if true.  I'm guessing we'll need some sort of an IF statement before each AddWindowsPrinterConnection line, but unfortunately my Google efforts have turned up nothing that looks applicable to our current situation.

Thanks for your help on this!
Option Explicit
Dim objNetwork, strUNCPrinter1, strUNCPrinter2, strUNCPrinter3, strUNCPrinter4
strUNCPrinter1 = "\\jetserve1\HP Color LaserJet 2605dn PCL6"
strUNCPrinter2 = "\\jetserve1\HPLaserJ4000"
strUNCPrinter3 = "\\jetserve1\KONICA"
strUNCPrinter4 = "\\jetserve1\Brother HL-5280DW"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.AddWindowsPrinterConnection strUNCPrinter2
objNetwork.AddWindowsPrinterConnection strUNCPrinter3
objNetwork.AddWindowsPrinterConnection strUNCPrinter4

WScript.Quit

Open in new window

0
Comment
Question by:JetPartsEngineering
4 Comments
 
LVL 2

Expert Comment

by:zcolton
ID: 34176289
You could use Group Policy preferences instead of a login script, if you domain level is high enough. I believe gp preferences are availabe in 2008. they work on XP and higher.
0
 
LVL 22

Accepted Solution

by:
Matt V earned 500 total points
ID: 34176295
"To obtain a list of the printers set up on a computer, you use code similar to that used to list the mapped network drives.

You use the EnumPrinterConnections method to obtain a WshCollection object where each network printer is made up of two elements in the collection. The even-positioned item contains the printers local name or port. The odd-positioned item contains the UNC name. As shown in Listing 3.39, you can use a For Next loop with the step value 2 to collect all the information you need.
"

Refer to http://technet.microsoft.com/en-us/library/ee156601.aspx

0
 

Author Comment

by:JetPartsEngineering
ID: 34176722
Sounds interesting - looks like I'll need to use the snippet below after line 7 to enumerate the printers.  How exactly would I compare the output of the enumeration to the printer names explicitly defines in the script?  I'm afraid my scripting skills are mostly limited to copy and (if it's a good day) paste.  Thanks again!
Set colPrinters = objNetwork.EnumPrinterConnections
For i = 0 to colPrinters.Count -1 Step 2
 Wscript.Echo colPrinters.Item(i) & vbTab & colPrinters.Item (i + 1)
Next

Open in new window

0
 
LVL 66

Expert Comment

by:johnb6767
ID: 34178725
Not a scripter by any means, but I am sure you could query "HKEY_CURRENT_USER\Printers\Connections" for the network path....

Like "HKEY_CURRENT_USER\Printers\Connections\//server/share/". If it finds it, move along....
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
youtube blocking politics 4 76
Infrastructure development vs software development 3 77
Adding a countdown to HTA 12 92
troubleshoot a python script 8 71
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …

685 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