To install a printer using a TCP/IP port, I run the following script, which works perfectly.
Just change the sections in RED to suit.
……………………………………………………………………………………………….
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
Install "10.10.65.23"
‘ Start the install of the printer
sub Install(strIP)
InstallPrinterPort strIP
end Sub
‘==================
strBasePrinter = "Lvl 22 North HP"
strPrinterName = "HP Color LaserJet CP3525 PCL 6"
strINFPath = "\\10.10.65.241\PrinterInstallScripts\Lvl22NorthHP\CP3525PrinterDriver\hpc3525c.inf"
strIPPort = "IP_10.10.65.23"
Set objShell = CreateObject("WScript.Shell")
strCommand = "cmd /c rundll32 printui.dll,PrintUIEntry /if /b """ & strBasePrinter & """ /f " & strINFPath & " /r """ & strIPPort & """ /m """ & strPrinterName & """ & /Z"
objShell.Run strCommand, 1, True
‘==================
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").SpawnInstance_
objNewPort.Name = "IP_" & strIP
objNewPort.Protocol = 1
objNewPort.HostAddress = strIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_
end Sub
NIce, Just what I was looking for . Thanks Marc You ROCK!
Nice Script, quick question? is it posible to add location and comment in the Printer Properties off this script?
Very nice script, but I keep getting the following error: “The arguments are invalid.” I’m a batch script writer, not vbs. What would cause this?
I also get that same error on XP SP3
It is the comment apostrophes that it cannot recognise, that is what gives the error
Its posible to write strINFPath = “c:\driver\autorun.inf ? Can it be autorun.inf ? I have error 0x800f0214
[…] Install a local TCP/IP printer using a VBS script | Marc Kean – Jul 14, 2009 · To install a printer using a TCP/IP port, I run the following script, which works perfectly. Just change the sections in RED to suit. …… […]
[…] Install a local TCP/IP printer using a VBS script | Marc Kean – Jul 14, 2009 · To install a printer using a TCP/IP port, I run the following script, which works perfectly. Just change the sections in RED to suit. …… […]
[…] Install a local TCP/IP printer using a VBS script | Marc Kean – Jul 14, 2009 · To install a printer using a TCP/IP port, I run the following script, which works perfectly. Just change the sections in RED to suit. …… […]
[…] Install a local TCP/IP printer using a VBS script | Marc Kean – Jul 14, 2009 · To install a printer using a TCP/IP port, I run the following script, which works perfectly. Just change the sections in RED to suit. …… […]
[…] Install a local TCP/IP printer using a VBS script | Marc Kean – Jul 14, 2009 · To install a printer using a TCP/IP port, I run the following script, which works perfectly. Just change the sections in RED to suit. …… […]