bfsharp
asked on
trying to automatically install standard tcp/ip printers
Hi Experts,
I am trying to connect to printers automatically on standard tcp/ip ports using a script. I have researched this extensively and have seen several ways to do it. The below code seemed to work well in its original state, I ran it and it installed the port and then installed Printer 1 on the port. When I entered my modifications, though I get errors, the most recent is Line 28 Char2 Error Genereic Failure Code 80041001 SWbemObjectEx. I am willing to concede this may have to do with the driver which is the most current for the HP Color Laserjet 5550, not sure if it is signed. How would I know? Also when I unzipped it I loaded it directly to C:\HPCLJ5550. The .inf and cab files are all in this folder. What else do you need to know? Help!
dim objWMIService
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ .\root\cim v2")
objWMIService.Security_.Pr ivileges.A ddAsString "SeLoadDriverPrivilege", True
Install "Printer Number 1", "HP Color LaserJet 5550", "C:\HPCLJ5550", "C:\HPCLJ5550\hpc5550d.inf ", "172.25.8.41"
sub Install(strPrinter, strDriverName, strDriverSource, strDriverInf, strIP)
' Install the specified printer, including driver and port
InstallPrinterDriver strDriverName, strDriverSource, strDriverInf
InstallPrinterPort strIP
InstallPrinter strPrinter, strDriverName, "IP_" & strIP
end sub
sub InstallPrinter(strName, strDriverName, strPortName)
' Install printer as detailed
dim objPrinter : Set objPrinter = objWMIService.Get("Win32_P rinter").S pawnInstan ce_
objPrinter.DriverName = strDriverName
objPrinter.PortName = strPortName '"IP_172.25.8.41"
objPrinter.DeviceID = strName
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Shared = false
objPrinter.Put_
end sub
sub InstallPrinterDriver(strDr iverName, strDriverSource, strDriverInf)
' Installs the printer driver
dim colInstalledDrivers, objDriver, strInstalledDriverName
' First check whether the driver is installed already
Set colInstalledDrivers = objWMIService.ExecQuery("S elect Name from Win32_PrinterDriver")
for each objDriver in colInstalledDrivers
strInstalledDriverName=Lef t(objDrive r.Name, Instr(1,objDriver.Name,"," )-1)
if strInstalledDriverName=str DriverName then exit sub ' We have a match, so no need to install driver
next
' Driver not present, so install it
Set objDriver = objWMIService.Get("Win32_P rinterDriv er")
objDriver.Name = strDriverName
objDriver.SupportedPlatfor m = "Windows NT x86"
objDriver.Version = "3"
objDriver.DriverPath = strDriverSource
objDriver.Infname = strDriverInf
objDriver.AddPrinterDriver (objDriver )
end sub
sub InstallPrinterPort(strIP)
' First check whether the port exists already
Set colInstalledPorts = objWMIService.ExecQuery _
("Select Name from Win32_TCPIPPrinterPort")
for each objPort in colInstalledPorts
if objPort.Name="IP_" & strIP then exit sub ' We have a result, so no need to add port
next
' Add new printer port
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort") .SpawnInst ance_
objNewPort.Name = "IP_" & strIP
objNewPort.Protocol = 1
objNewPort.HostAddress = strIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_
end sub
I am trying to connect to printers automatically on standard tcp/ip ports using a script. I have researched this extensively and have seen several ways to do it. The below code seemed to work well in its original state, I ran it and it installed the port and then installed Printer 1 on the port. When I entered my modifications, though I get errors, the most recent is Line 28 Char2 Error Genereic Failure Code 80041001 SWbemObjectEx. I am willing to concede this may have to do with the driver which is the most current for the HP Color Laserjet 5550, not sure if it is signed. How would I know? Also when I unzipped it I loaded it directly to C:\HPCLJ5550. The .inf and cab files are all in this folder. What else do you need to know? Help!
dim objWMIService
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
objWMIService.Security_.Pr
Install "Printer Number 1", "HP Color LaserJet 5550", "C:\HPCLJ5550", "C:\HPCLJ5550\hpc5550d.inf
sub Install(strPrinter, strDriverName, strDriverSource, strDriverInf, strIP)
' Install the specified printer, including driver and port
InstallPrinterDriver strDriverName, strDriverSource, strDriverInf
InstallPrinterPort strIP
InstallPrinter strPrinter, strDriverName, "IP_" & strIP
end sub
sub InstallPrinter(strName, strDriverName, strPortName)
' Install printer as detailed
dim objPrinter : Set objPrinter = objWMIService.Get("Win32_P
objPrinter.DriverName = strDriverName
objPrinter.PortName = strPortName '"IP_172.25.8.41"
objPrinter.DeviceID = strName
objPrinter.Location = ""
objPrinter.Network = True
objPrinter.Shared = false
objPrinter.Put_
end sub
sub InstallPrinterDriver(strDr
' Installs the printer driver
dim colInstalledDrivers, objDriver, strInstalledDriverName
' First check whether the driver is installed already
Set colInstalledDrivers = objWMIService.ExecQuery("S
for each objDriver in colInstalledDrivers
strInstalledDriverName=Lef
if strInstalledDriverName=str
next
' Driver not present, so install it
Set objDriver = objWMIService.Get("Win32_P
objDriver.Name = strDriverName
objDriver.SupportedPlatfor
objDriver.Version = "3"
objDriver.DriverPath = strDriverSource
objDriver.Infname = strDriverInf
objDriver.AddPrinterDriver
end sub
sub InstallPrinterPort(strIP)
' First check whether the port exists already
Set colInstalledPorts = objWMIService.ExecQuery _
("Select Name from Win32_TCPIPPrinterPort")
for each objPort in colInstalledPorts
if objPort.Name="IP_" & strIP then exit sub ' We have a result, so no need to add port
next
' Add new printer port
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort")
objNewPort.Name = "IP_" & strIP
objNewPort.Protocol = 1
objNewPort.HostAddress = strIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_
end sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brian