Solved

Network printer installation script

Posted on 2008-10-31
6
592 Views
Last Modified: 2013-12-15
I am trying to write script for Windows 2003 AD domain that will check if printer with given name does exist and if not installs new printer queue. Currently there is no print server on the network and I want to keep printing independent from servers (if the server is down, the users still needs to print). There are some HP LaserJet 1020's and Epson color printer connected via 3rd party jet direct to the network. Printers are installed with TCP/IP port configured with printer IP (IP_192.168.1.101). All the scripts I found are working with \\servername\printername.

I also do not know how tell the script which drivers to use if the OS does not recognize the printer.

It is on small network with 16 computers, but it is still time consuming to install new network printer on all of them manually.
0
Comment
Question by:haldoxp
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
sk_raja_raja earned 500 total points
Comment Utility
0
 
LVL 18

Expert Comment

by:sk_raja_raja
Comment Utility
0
 
LVL 5

Expert Comment

by:marques_salazar
Comment Utility
This is what I use (vbs):

Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\servername\printername"
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 3

Author Comment

by:haldoxp
Comment Utility
First link seems to be exactly what I need.
All other links are for server name \ printer name scenario.
0
 
LVL 3

Author Comment

by:haldoxp
Comment Utility
After some testing the script from first link is working for me perfectly. Only issue is this script cannot be used on Windows Server 2003. SWbemObjectEx gives "Access denied". But I can live with this.
wscript.Echo "This Script will Install the HP LaserJet 1022n (location) on your computer and set it as the default printer. If you want another default printer you will need to set it after this printer is installed. Script will now run, takes about 45 seconds. During that time you will see no screen acttivity until it finishes with the printer installation."

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objNewPort = objWMIService.Get _

    ("Win32_TCPIPPrinterPort").SpawnInstance_

 

objNewPort.Name = "IP_192.168.1.115"

objNewPort.Protocol = 1

objNewPort.HostAddress = "192.168.1.115"

objNewPort.PortNumber = "9100"

objNewPort.SNMPEnabled = False

objNewPort.Put_

 

Set objDriver = objWMIService.Get("Win32_PrinterDriver")

 

objDriver.Name = "HP LaserJet 1022n"

objDriver.SupportedPlatform = "Windows NT x86"

objDriver.Version = "3"

objDriver.Infname = "Z:\INSTALL\PrinterDrivers\LaserJet1020-1022Drivers\HPLJ1020.INF"

intResult = objDriver.AddPrinterDriver(objDriver)

 

 

 

Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

 

objPrinter.DriverName = "HP LaserJet 1022n"

objPrinter.PortName   = "IP_192.168.1.115"

objPrinter.DeviceID   = "HP LaserJet 1022n (location)"

objPrinter.Location = "location"

objPrinter.Network = True

objPrinter.Shared = False

objPrinter.Put_

'objPrinter.SetDefaultPrinter "HP LaserJet 1022n (location)"

 

wscript.Echo "Installation of HP LaserJet 1022n (location) has completed, and Set as Default, Change Default if you had another printer set as your default."

Open in new window

0
 
LVL 3

Author Closing Comment

by:haldoxp
Comment Utility
Thanks :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When I recently replaced my image transfer kit on my office HP color laserjet 5550dn printer, I had a slight problem.  The left bracket that holds the transfer kit got stuck in the upright locked position instead of being at a 45 degree angle facing…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

7 Experts available now in Live!

Get 1:1 Help Now