Solved

Modify printer logon script to check if printers already exist

Posted on 2010-11-19
4
801 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …

790 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