Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 618
  • Last Modified:

Network printer installation script

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
haldoxp
Asked:
haldoxp
  • 3
  • 2
1 Solution
 
sk_raja_rajaCommented:
0
 
marques_salazarCommented:
This is what I use (vbs):

Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\servername\printername"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
haldoxpAuthor Commented:
First link seems to be exactly what I need.
All other links are for server name \ printer name scenario.
0
 
haldoxpAuthor Commented:
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
 
haldoxpAuthor Commented:
Thanks :)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now