Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Install printers via TCP/IP Port w/ Drivers VBscript Help

Status
Not open for further replies.

QBNKRaCKeR

IS-IT--Management
Nov 3, 2010
5
US
Hi everybody,
I’m writing a script to install network printers via TCP/IP ports and the drivers are not in Drivers.cab. I get a generic error whenever I execute the script and I realized that the drivers are not being installed. I’ve looked at tons of examples on how to install the drivers but I cannot see what is wrong with my code. I know all the information is correct because I was able to install the printer via a batch file. The only wildcard is the driver path, but there is only one DLL in the driver folder and I’m assuming that it is the correct one. Any help will be greatly appreciated.

Code:
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set Shell = WScript.CreateObject("WScript.Shell")
CompName = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & CompName & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_


objNewPort.Name = "IP_192.168.105.31"
objNewPort.Protocol = 1
objNewPort.HostAddress = "192.168.105.31"
objNewPort.SNMPEnabled = False
objNewPort.Put_


objDriver.Name ="HP LaserJet 4345 mfp PCL 6"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
objDriverPath = "\\rcnyfs1\Technology\drivers\Print drivers\HP LJ4345 MFP\hpbicoin.dll"
objInfname = "\\rcnyfs1\Technology\drivers\Print drivers\HP LJ4345 MFP\hpc4345c.inf"
intResult = objDriver.AddPrinterDriver(objDriver)

objPrinter.DriverName ="HP LaserJet 4345 mfp PCL 6"
objPrinter.PortName ="IP_192.168.105.31"
objPrinter.DeviceID = "LJ 4345"
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Shared = false
objPrinter.ShareName = ""
objPrinter.Put_
 
Replace this:
objDriverPath
with this:
objDriver.DriverPath

And this:
objInfname
with this:
objDriver.Infname

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
/facepalm
It's still not working but we have made progress. It looks like it's at least trying to install the driver but it still fails when I try to put the printer. The ports are being created but the driver is still not being installed.

New Code
Code:
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set Shell = WScript.CreateObject("WScript.Shell")
CompName = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & CompName & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_


objNewPort.Name = "IP_192.168.105.31"
objNewPort.Protocol = 1
objNewPort.HostAddress = "192.168.105.31"
objNewPort.SNMPEnabled = False
objNewPort.Put_


objDriver.Name ="HP LaserJet 4345 mfp PCL 6"
'objDriver.SupportedPlatform = "Windows NT x86"
'objDriver.Version = "3"
objDriver.DriverPath = "\\rcnyfs1\Technology\drivers\Print drivers\HP LJ4345 MFP\hpbicoin.dll"
objDriver.Infname = "\\rcnyfs1\Technology\drivers\Print drivers\HP LJ4345 MFP\hpc4345c.inf"
intResult = objDriver.AddPrinterDriver(objDriver)

objPrinter.DriverName ="HP LaserJet 4345 mfp PCL 6"
objPrinter.PortName ="IP_192.168.105.31"
objPrinter.DeviceID = "LJ 4345"
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Shared = false
objPrinter.ShareName = ""
objPrinter.Put_
[\code]
 
sorry wrong slash
Code:
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set Shell = WScript.CreateObject("WScript.Shell")
CompName = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & CompName & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_


objNewPort.Name = "IP_192.168.105.31"
objNewPort.Protocol = 1
objNewPort.HostAddress = "192.168.105.31"
objNewPort.SNMPEnabled = False
objNewPort.Put_


objDriver.Name ="HP LaserJet 4345 mfp PCL 6"
'objDriver.SupportedPlatform = "Windows NT x86"
'objDriver.Version = "3"
objDriver.DriverPath = "\\rcnyfs1\Technology\drivers\Print drivers\HP LJ4345 MFP\hpbicoin.dll"
objDriver.Infname = "\\rcnyfs1\Technology\drivers\Print drivers\HP LJ4345 MFP\hpc4345c.inf"
intResult = objDriver.AddPrinterDriver(objDriver)

objPrinter.DriverName ="HP LaserJet 4345 mfp PCL 6"
objPrinter.PortName ="IP_192.168.105.31"
objPrinter.DeviceID = "LJ 4345"
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Shared = false
objPrinter.ShareName = ""
objPrinter.Put_
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top