Share with:


Our campus, Faculty of Architecture, VGTU is moving to the totally new subnet. As we use DHCP for IP distribution, no real problems except `sed` are going to appear.
The pleasing moment is we are getting a fresh IP range.
The headache is TCP/IP printers.

WPKG has good printer addition/ installation guide in http://wpkg.org/Printer_configuration , but it does not cover changing IP port numbers.
As a CEO on all computer infrastructure, I need to find any solution to make the movement smoothly.

I was unable to find a ready-made solution, and in-house tool appeared after several hours in the Net.
I need to apologize for bugs and errors, as it is the first (and hopefully the last) VB script. It uses WMI. Testing box was W7, x64.
Maybe someone will find it useful.

Call the file chprinterport.vbs

Set args = WScript.Arguments
if args.Count < 2 then Wscript.Echo " " Wscript.Echo " Change IP ports for TCP/IP printers on Windows boxes" Wscript.Echo " " Wscript.Echo " Usage: cscript chprinterport.vbs old_TCP/IP_port new_TC/IP_port"
Wscript.Echo " "
Wscript.Echo " eg: cscript chprinterport.vbs 192.168.1.2 192.168.2.3 will change"
Wscript.Echo " port IP from 192.168.1.2 to 192.168.2.3"
Wscript.Echo " "
Wscript.Echo " Partial match is possible, so:"
Wscript.Echo " cscript chprinterport.vbs 192.168 210.23 will change"
Wscript.Echo " port IP from 192.168.x.y to 210.23.x.y"
Wscript.Echo " "
Wscript.Echo " Inspired by:"
Wscript.Echo " http://wpkg.org/Printer_configuration"
Wscript.Echo " http://gallery.technet.microsoft.com/ScriptCenter/en-us/5777dc6a-9783-43d7-ac8e-fd3bd739690c"
Wscript.Echo " http://www.pcreview.co.uk/forums/showpost.php?s=8a077fc479806d3fc03bf734d57b357f&p=5622799&postcount=6"
Wscript.Echo " "
Wscript.Echo " License - BSD"
Wscript.Echo " "
Wscript.Echo " (c) 2010 ejs@seniejitrakai.net, ejs@ar.vgtu.lt"
Wscript.Echo " http://ejs.seniejitrakai.net"
else
oldIPAddress = args.Item(0)
newIPAdress = args.Item(1)
Dim strComputer
Dim Result
strComputer = "."
Result = ""
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate,(LoadDriver)}!\\" & strComputer & _
"\root\cimv2")
Set colPorts = objWMIService.ExecQuery ("Select * from Win32_TCPIPPrinterPort")
For Each objPort in colPorts
wscript.echo "Found TCP/IP printer port: " & objPort.HostAddress & ", named " & objPort.Name
if UCase(Mid(objPort.HostAddress, 1, Len(oldIPAddress))) = oldIPAddress Then
objPort.HostAddress = newIPAdress & Mid(objPort.HostAddress, Len(oldIPAddress)+1)
Wscript.Echo "New Printer port: " & objPort.HostAddress
Result = objPort.Put_
If Len(Result) > 0 Then
WScript.Echo "Updated TCP/IP printer port: " & objPort.HostAddress & ", named " & objPort.Name
Else
WScript.Echo "Error " & Result & " updating TCP/IP printer port: " & objPort.HostAddress
WScript.Quit
End If
end if
Next
end if