?
Solved

Modify printer logon script to check if printers already exist

Posted on 2010-11-19
4
Medium Priority
?
818 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 2000 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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Make the most of your online learning experience.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

862 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