• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2272
  • Last Modified:

Howto change/reassign printer IP ports to new printer IP ports with scripting

Please help!

The company do have more than 200 PC logged into a NT40 Domain.
We are going to upgrade to Windows 2003 Server with AD.

Before this our IP addresses also have to be changed. We have public IP addresses, which we
must change to privat IP adresses for the whole system. This task must be done first.

This gives us a problem, as all printers are connected directly to the printers with different
IP port assignments on the client machines (all XP Prof). We want to continue with this solution.

We use:  HP Standard TCP/IP Port,   Lexmark Network Port,   OKI LPR Port, Crown Port+   and   Standard TCP/IP Port.

We tried exporting the printer specific registry keys like
HKEY_LOCAL_MACHINE\SOFTWARE\Hewlett-Packard - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print -
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\print - etc

In a test system we were able to make search and replace on the IP adresses in the exported REG files.
Ufortunately there are some binary data in the reg files containing the IP adresses of the printer ports which we could not replace with the new IP adresses.

Is there an easier solution for our project to change IP printer port assignments on client machines.

Sincirely, Birger

1 Solution
Set Static addresses for the printers. Then set the addresses on the clients globally.


I realize you mentioned that you would like to "continue to use this solution" - but this may be an ideal time to setup a print server in your organization to optimize your printing environment.  

Once you have a server(s) setup with all of your printers, you can share them out to clients - and then map them to the clients in a login script.  In that same login script you can delete old printers, add new ones, etc.

This allows for centralized control in a network - which would not be a bad thing with 200+ PCs in your organization.  

Please let me know your thoughts.

birgeradslhomedkAuthor Commented:
You are right about this.

But our network struckture has to be optimized so that communication
between client and printer is as close as possible to each other.  This
is because of bottlenecks in the bandwidth and some VPN tunnels.
Client/server application, terminal services and other programs must have full bandwidth.  

Upgrading the network is a project for the next year.

Thanks for the response.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

birgeradslhomedkAuthor Commented:
Next year we also will have a new Printer Output system.
For now we have to use the solution I mentioned

About "Set Static addresses for the printers".
They have IP adresses given by Reserverved DHCP IP adresses. No problem here.

About "Then set the addresses on the clients globally"
I am not sure what you mean with this globally.

What I need is an automatically change/reassignment of the client Printer IP ports.


Understood - makes sense.

If in fact you can do this by registry, how will you implement this?  Manually or via script, etc?


Hopefully these links can assist you-

PRNPORT.VBS - Printer Port Control

Command Line Printer Control - Windows 2000 & XP

birgeradslhomedkAuthor Commented:

Implementing is no problem. We have succeded with that.
Batch file in login script. Using reg command.

What we have tried is
Exporting relevant registry keys with reg command to REG files on a centralised location for each client.
In the REG files we have replaced the old IP references and replace with new IP adresses

The shift to new IP adresses will be done over a weekend:

On the 1st logon the clients will have a special script where
Old registry keys wil be deleted and the edited REG files will be imported

All this works fine in the test system.

The problem in this this method is that the REG files have binary stored information
about the printer IP ports. The good side is that we can handle different
Network Printer Ports from several printer deliverer.
On way is to make a machine with the new adresses, and the exporting them. The new binary values from the REG file
can then be added to the modified REG files by search and replace utility

What I hoped for is a smart script in a loggon script, that just finds printerports and the reassigns them automatically with new IP's,
which of couse must be putted into the script.

Sincirely Birger

birgeradslhomedkAuthor Commented:

I have seen those links and are aware of them.

I have just not found a way to change a port value with a script. It is possible to
add and delete. But I want to change the ports.

Also they are only for Standard IP/TCP ports.


I realize that changing would be optimal, but is it possible to delete and then to readd?

birgeradslhomedkAuthor Commented:

From the exported the reg files we created temporary REG files where we
added the minus sign before the HKLM and rerun it tvice in the logon script. The information of the
ports are remove this way. This must be done to get rid of the old port assigment.
Afterwards we added the modified Reg files.

I think we have to do search and replace of the binary values in the exported REG files.

I did it for two printers and they worked fine in the test enviroment.

It would have been easier with a script designed only for reassigning IP ports for
already existing printers on the client machine.

"But our network struckture has to be optimized so that communication
between client and printer"


Try this script, and tell me if I understood your needs

' --------------- prnIPchange.vbs ---------------
'Change all ip occurrences in printer tcp  
' Gas ver 0.01
sub FindPRNandChangeIP (ip,newip)
     strComputer = "."
     Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colPorts =  objWMIService.ExecQuery _
    ("Select * from Win32_TCPIPPrinterPort")
    For Each objPort in colPorts
         if  objPort.HostAddress = OldIp       then
               cngPRNport objPort.Name, NewIp
         end if            
end sub

sub cngPRNport (Name,newip)
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set objNewPort = objWMIService.Get _
  objNewPort.Name = Name
  objNewPort.HostAddress = newip
end sub
sub listPRNport
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colPorts =  objWMIService.ExecQuery _
    ("Select * from Win32_TCPIPPrinterPort")
   For Each objPort in colPorts
    Wscript.Echo "Description: " & objPort.Description
    Wscript.Echo "Host Address: " & objPort.HostAddress
    Wscript.Echo "Name: " & objPort.Name
    Wscript.Echo "Port Number: " & objPort.PortNumber
    Wscript.Echo "Protocol: " & objPort.Protocol
    Wscript.Echo "SNMP Community: " & objPort.SNMPCommunity
    Wscript.Echo "SNMP Dev Index: " & objPort.SnMPDevIndex
    Wscript.Echo "SNMP Enabled: " & objPort.SNMPEnabled
end sub
Dim oArgs,Counter
Set oArgs = WScript.Arguments
Counter = oArgs.Count
If (Counter <> 2) Then
   WScript.echo "Wrong parameters"
   WScript.echo "---------list printer ports-------------------"
   WScript.echo "-------------------------------------------"
   WScript.echo "Wrong parameters"
   WScript.echo "Usage:  cscript prnIPchange.vbs OldIp NewIp"
   WScript.Quit 1
end if
FindPRNandChangeIP OldIp, NewIp

set oArgs=Nothing
birgeradslhomedkAuthor Commented:
Thank you forthe script

Indeed it changes the value for the printer ports "Standard TCP/IP Port".
But it seems that the keyname still is the old one.

Also it can not change the other types of IP port assignments.

I think I will use my way. It has only to be done once.

Thank you all for help


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now