Script to find replace Ip's on local printer ports?

devinp619
devinp619 used Ask the Experts™
on
Hello,
We are switching over our internal ip range, does anyone know of a script or what's needed to make a script to change the ip address on Local Tcpip printer ports?  I'm looking to add it to a login script so I don't have to run around to every desktop, login as each user that uses it and change their printer ports. (Mostly 2000 pro some xp).

For example if I could just list every ip address of the current network printers and do an if exists.....replace..... kind of deal.  This would be a HUGE help :).  Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I don't know of any script, but you can:

a) look up which users are authorized for the specific IP address of the printer using your AD.
b) export the registry entry for the each specific IP from your own machine.
c) have it (through group policy, login script, etc...) when the user logon run the .reg file to replace the existing entry in the registry.

d) if you have remote management you can also do the more specific ones using remote management.

Registry search for the IP to locate the key and export or look
\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports

hope that help.....  may be someone has a script or program to read the IP address in the key and do a compare before importing the .reg file.

cheers
you can set up the new printers on one machine, export the registry entries and import them in the login script
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\(port name)

Use con2prt
http://support.microsoft.com/?kbid=181663

or rundll
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q189/1/05.ASP&NoWebContent=1

(better examples here: http://www.robvanderwoude.com/index.html )

Commented:
chicagoan,

Why not just put in "regedit xxx.reg" in the script via policy as I suggested?

cheers
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

why not indeed!
I fully support that avenue!
there are others, depending on the administrator's familiarity and comfort level

Author

Commented:
Thank you guys for the comments, I'll play around with them a little and close out soon, Thank you very much.
Try this, there's also a csv file with the following data

Stores HP6P              172.16.1.55
Path Micro Laser         172.16.1.57
GONH_HP2200         172.16.1.58
CRMH_HP4600          172.16.1.59



'Printer Update
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections

For i = 0 to Printers.Count - 1 step 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("y:\printerip.csv", 1)
      Do Until objTextFile.AtEndOfStream
          strNextLine = objTextFile.Readline
          arrServiceList = Split(strNextLine , ",")
            ip = arrServiceList(1)
            newip = arrServiceList(0)
              if Printers.Item(i) = "IP_" & ip then
                 print1 = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\" & printers.item(i+1) & "\"
                 print2 = print1 & "DsSpooler\"
                        print3 = "HKLM\system\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\"
                 print4 = print3 & Printers.Item(i) & "\"
                 print5 = "HKLM\system\CurrentControlSet\Control\Print\Printers\" & printers.item(i+1) & "\"
                 print6 = print5 & "DsSpooler\"
                 WScript.Echo "Printer " &Printers.Item(i+1) &" has been updated"
                 WSHShell.RegWrite print1 & "Port", "IP_" & newip
                 WSHShell.RegWrite print2 & "PortName", "IP_" & newip
                 WSHShell.RegWrite print4 & "IPaddress", newip
                 WSHShell.RegWrite print5 & "Port", "IP_" & newip
                 WSHShell.RegWrite print6 & "PortName", "IP_" & newip
              end if
      Loop
next
WScript.Echo "Printers have been updated"
change from IP to Host name printing

'Printer Update
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections

For i = 0 to Printers.Count - 1 step 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("y:\printerip.csv", 1)
      Do Until objTextFile.AtEndOfStream
          strNextLine = objTextFile.Readline
          arrServiceList = Split(strNextLine , ",")
'          Wscript.Echo "Printer name: " & arrServiceList(0) &" IP: " & arrServiceList(1)
            ip = arrServiceList(1)
            newip = arrServiceList(0)
              if Printers.Item(i) = "IP_" & ip then
                 print3 = "HKLM\system\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\"
                 print4 = print3 & Printers.Item(i) & "\"
                 WSHShell.RegWrite print4 & "HostName", newip
                 WSHShell.RegWrite print4 & "IPAddress", ""
                 WScript.Echo "Printer " &Printers.Item(i+1) &" has been updated"
              end if
      Loop
next
WScript.Echo "Printers have been updated"
'end Printer update

Commented:
So how did this work? What information was stored in the CSV file?

Commented:

I created a csv file containing  old , new IP address of the printers I want to chang. Im getting an the error however:  (wondering if I need more in the csv file).
 
Windows script error
 
Line: 22
Char : 18
Error: Object required:wshshell
Code:800a01a8
Souce: Microsoft VBscript Runtime error
 
 
 
'Printer Update
 
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections
 
For i = 0 to Printers.Count - 1 step 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\temp\test.txt", 1)
      Do Until objTextFile.AtEndOfStream
          strNextLine = objTextFile.Readline
          arrServiceList = Split(strNextLine , ",")
            ip = arrServiceList(1)
            newip = arrServiceList(0)
              if Printers.Item(i) = "IP_" & ip then
                 print1 = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\" & printers.item(i+1) & "\"
                 print2 = print1 & "DsSpooler\"
                        print3 = "HKLM\system\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\"
                 print4 = print3 & Printers.Item(i) & "\"
                 print5 = "HKLM\system\CurrentControlSet\Control\Print\Printers\" & printers.item(i+1) & "\"
                 print6 = print5 & "DsSpooler\"
                 WScript.Echo "Printer " &Printers.Item(i+1) &" has been updated"
                 WSHShell.RegWrite print1 & "Port", "IP_" & newip
                 WSHShell.RegWrite print2 & "PortName", "IP_" & newip
                 WSHShell.RegWrite print4 & "IPaddress", newip
                 WSHShell.RegWrite print5 & "Port", "IP_" & newip
                 WSHShell.RegWrite print6 & "PortName", "IP_" & newip
              end if
      Loop
next
WScript.Echo "Printers have been updated"
 


if i remember the CSV file only had 2 fields "name","ipadress"

Commented:
I'm getting some scripting errors, were any further modifcations made to the script?
 
it was four years ago but i don't believe so

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial