Solved

Network printer installation script

Posted on 2008-10-31
6
607 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

Printers have changed substantially in the last 30 or so years, not just in technical capabilities but in cost and usage as well.  Printers were originally used for interfacing with the operator, not necessarily for printing copy or pictures. In …
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
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…

729 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