Hello, I found this thread, and am trying to get this script to work.
When I run the script it just seems to jump straight through to the end and says "Printer installation complete." when nothing happens.
It looks like there is a menu to choose which printer to install, or install all of them. This would be perfect for my situation if I could get it to work, as is when I run the scrip that selection doesn't come up at all.
I am very new to this type of scripting, so I am probably making an easy mistake here.
I would be installing the printers with externally defined drivers, so I un-commented those lines and added my own printer names and IP addresses. I'm not sure where this is failing.
Any help would be much appreciated. Thanks
Please see my slightly modified code below:
When I run the script it just seems to jump straight through to the end and says "Printer installation complete." when nothing happens.
It looks like there is a menu to choose which printer to install, or install all of them. This would be perfect for my situation if I could get it to work, as is when I run the scrip that selection doesn't come up at all.
I am very new to this type of scripting, so I am probably making an easy mistake here.
I would be installing the printers with externally defined drivers, so I un-commented those lines and added my own printer names and IP addresses. I'm not sure where this is failing.
Any help would be much appreciated. Thanks
Please see my slightly modified code below:
Code:
'----------------------------------------------'
'----------------------------------------------'
' '
' Script to automate TCP/IP printer installs '
' (Andrew Levine - 12/2004) '
' '
'----------------------------------------------'
'----------------------------------------------'
Set WSHNetwork = WScript.CreateObject("WScript.Network")
set shell = WScript.CreateObject( "WScript.Shell" )
CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
Set oShell = WScript.CreateObject("WScript.shell")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
sub createPort (name, ip)
objNewPort.Name = name
objNewPort.Protocol = 1
objNewPort.HostAddress = ip
objNewPort.SNMPEnabled = False
objNewPort.Put_
end sub
sub addPrinter (driver, port, name)
objPrinter.DriverName = driver
objPrinter.PortName = port
objPrinter.DeviceID = name
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Shared = false
objPrinter.ShareName = ""
objPrinter.Put_
end sub
message = "Please choose a printer to install:" & vbCrLf & vbCrLf & "1: All Printers" & vbCrLf & "2: HP4200 North" & vbCrLf & "3: HP8150 Library Desk" & vbCrLf & "4: HP8500 Color PS" & vbCrLf& vbCrLf & vbCrLf & "Please enter 1-5 (leave blank to quit):"
title = "Install Printers - BCEHFP"
'------------------'
'Add printer ports:'
'------------------'
createPort "HPLJ8150_Library_Desk", "10.18.65.238"
createPort "CanoniR7095_Library_Copy", "10.18.66.249"
createPort "RICOHMPC300SR_Main_Office", "10.18.65.247"
'----------------------------------------------'
'Install printers with drivers native to WinXP:'
'----------------------------------------------'
' TCP/IP Port Name Display Name
' -------------------- -----------------
addPrinter "HP Color LaserJet 8500 PS", "HP8500_Exec_color", "HP8500 Color PS"
'addPrinter "HP LaserJet 4200 PS", "HP4200_BCEHFP_North", "HP4200 North PS"
'addPrinter "HP LaserJet 4200 PCL 6", "HP4200_BCEHFP_North", "HP4200 North"
'-------------------------------------------------' Display name
'Install printers with externally defined drivers:' for printer Driver location Port name Driver name in .inf file
'-------------------------------------------------' ----------- --------------------------------- ------------ -----------------------
oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP LJ 8150 Library Desk"" /f C:C:\HP LJ8150\HP8150c.INF /r ""HPLJ8150_Library_Desk"" /m ""HP LaserJet 8150 Series PCL6""" ,,true
'oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP8150 South PS"" /f U:\instalxp\hp8150ps\HP8150PS.INF /r ""HP8150_BCEHFP_South"" /m ""HP LaserJet 8150 PS""" ,,true
msgbox ("Printer installation complete.")