Solved

Network printer installation script

Posted on 2008-10-31
6
605 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
sk_raja_raja earned 500 total points
ID: 22854341
0
 
LVL 18

Expert Comment

by:sk_raja_raja
ID: 22854350
0
 
LVL 5

Expert Comment

by:marques_salazar
ID: 22854367
This is what I use (vbs):

Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\servername\printername"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:haldoxp
ID: 22876253
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
ID: 22893835
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
ID: 31513851
Thanks :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

737 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