Thursday 21 February 2008

Add a printer using TCP port

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "IP_(ip address of your printer)"
objNewPort.Protocol = 1
objNewPort.Queue = "(name of your printer)"
objNewPort.HostAddress = "(ip address of your printer)"
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False


'prevents timeout WMI problem
On Error Resume Next
objNewPort.Put_
ErrCounter = 0
Do While (Err.Number <> 0) And (ErrCounter < 3)
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Err.Number = 0
objNewPort.Put_
ErrCounter = ErrCounter + 1
Loop
On Error GoTo 0

No comments: