Link to home
Start Free TrialLog in
Avatar of devinp619
devinp619

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of Gnart
Gnart

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 )
Avatar of Gnart
Gnart

chicagoan,

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

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

ASKER

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
So how did this work? What information was stored in the CSV file?

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"
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