Add printer port

AddPrinterTcpIPport.vbs


' http://www.experts-exchange.com/Operating_Systems/Win2000/Q_21018860.html
' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_tcpipprinterport.asp
' http://www.microsoft.com/technet/community/scriptcenter/printing/scrprn09.mspx

' Arguments to be: ip, proto
'       if raw: port
'       if lpr: queue name

if Wscript.Arguments.Count = 0 then
        WScript.Echo "Usage: [cscript | wscript] AddPrinterTcpIPport.vbs ip proto [extra]"
        WScript.Quit 1
end if

IP = Wscript.Arguments.Item(0)
proto = Wscript.Arguments.Item(1)
'extra = Wscript.Arguments.Item(2)
'WScript.Echo Arg1

Set objWMIService = GetObject("winmgmts:")
'Const IP = "192.168.1.56"
'Set IP = Wscript.Arguments.Named("ip")

Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "IP_"&IP
objNewPort.HostAddress = IP

' Protocol: 0 = raw, 1 lpr => non 1 = raw, & 2 = lpr
if proto = 1 then
'WScript.echo "proto is 0"
        objNewPort.Protocol = 1
'       objNewPort.PortNumber = "9100"
        objNewPort.PortNumber = extra
else
'WScript.echo "proto is 1"
        objNewPort.Protocol = 2
        objNewPort.Queue = "directe"
end if
objNewPort.SNMPEnabled = False

'WScript.echo objNewPort.Name
'WScript.echo objNewPort.PortNumber
'WScript.echo objNewPort.Protocol

objNewPort.Put_

last edited 2005-01-20 15:58:35 by eminem