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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
chicagoan,
Why not just put in "regedit xxx.reg" in the script via policy as I suggested?
cheers
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
I fully support that avenue!
there are others, depending on the administrator's familiarity and comfort level
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("WScr ipt.Networ k")
Set Printers = WshNetwork.EnumPrinterConn ections
For i = 0 to Printers.Count - 1 step 2
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
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\W indows NT\CurrentVersion\Print\Pr inters\" & printers.item(i+1) & "\"
print2 = print1 & "DsSpooler\"
print3 = "HKLM\system\CurrentContro lSet\Contr ol\Print\M onitors\St andard TCP/IP Port\Ports\"
print4 = print3 & Printers.Item(i) & "\"
print5 = "HKLM\system\CurrentContro lSet\Contr ol\Print\P rinters\" & 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"
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("WScr
Set Printers = WshNetwork.EnumPrinterConn
For i = 0 to Printers.Count - 1 step 2
Set objFSO = CreateObject("Scripting.Fi
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\W
print2 = print1 & "DsSpooler\"
print3 = "HKLM\system\CurrentContro
print4 = print3 & Printers.Item(i) & "\"
print5 = "HKLM\system\CurrentContro
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("WScr ipt.Networ k")
Set Printers = WshNetwork.EnumPrinterConn ections
For i = 0 to Printers.Count - 1 step 2
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
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\CurrentContro lSet\Contr ol\Print\M onitors\St andard 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
'Printer Update
Set WshNetwork = WScript.CreateObject("WScr
Set Printers = WshNetwork.EnumPrinterConn
For i = 0 to Printers.Count - 1 step 2
Set objFSO = CreateObject("Scripting.Fi
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\CurrentContro
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("WScr
Set Printers = WshNetwork.EnumPrinterConn
For i = 0 to Printers.Count - 1 step 2
Set objFSO = CreateObject("Scripting.Fi
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\W
print2 = print1 & "DsSpooler\"
print3 = "HKLM\system\CurrentContro
print4 = print3 & Printers.Item(i) & "\"
print5 = "HKLM\system\CurrentContro
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
HKEY_LOCAL_MACHINE\SYSTEM\
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 )