Solved

Modify printer logon script to check if printers already exist

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

770 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