Solved

Modify printer logon script to check if printers already exist

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now