Solved

Network printer installation script

Posted on 2008-10-31
6
593 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Learn about cloud computing and its benefits for small business owners.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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