Printer IP replacement - Help needed (Full Version)

All Forums >> [Scripting Technologies] >> VB Script



Message


tonyh -> Printer IP replacement - Help needed (9/17/2008 10:31:39 PM)

The following scripts works fine with admin rights, won’t work with-out. I tried to apply a registry fix to elevate the rights with GP but was unsuccessful.
The CSV file contains the IP address of the new printer, old Printer
Thoughts?

Set WshShell = WScript.CreateObject("WScript.Shell")
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:\printerIP.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\Monit ors\Standard TCP/IP Port\Ports\"
print4 = print3 & Printers.Item(i) & "\"
print5 = "HKLM\system\CurrentControlSet\Control\Print\Print ers\" & printers.item(i+1) & "\"
print6 = print5 & "DsSpooler\"
WScript.Echo "Printer " &Printers.Item(i+1) &" has been updated. Please restart your system"
WSHShell.RegWrite print1 & "Port", "IP_" & newip
WSHShell.RegWrite print2 & "PortName", "IP_" & newip
WSHShell.RegWrite print5 & "Port", "IP_" & newip
WSHShell.RegWrite print6 & "PortName", "IP_" & newip
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"HostName", ""
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"HWAddress", ""
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"IPAddress", newip
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"PortNumber", "9100", "REG_DWORD"
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"Protocol", "1", "REG_DWORD"
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"SNMP Community", "public", "REG_SZ"
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"SNMP Enabled", "1", "REG_DWORD"
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"SNMP Index", "1", "REG_DWORD"
WSHShell.RegWrite print3 & "IP_" & newip & "\" &"Version", "1", "REG_DWORD"
end if
Loop
next
'WScript.Echo " Your Printers have been updated. A reboot is required before changes will take




rbennett806 -> RE: Printer IP replacement - Help needed (9/26/2008 10:10:14 AM)

Since nobody has picked this one up.... What exactly is it that you're trying to do with this script? If you're doing printer replacements, maybe think about doing something like...

Set objNetwork = Wscript.CreateObject("WScript.Network")
strPrinter = ?????
strPrintQueue = ????
'removing a printer
objNetwork.RemovePrinterConnection strPrinter, True, True
'adding a printer
objNetwork.AddWindowsPrinterConnection strPrintQueue


And if your users can't add printers, either adjust a domain GPO (or local) setting to grant them the right, or else maybe try running this as a Startup script. And of course that's just a rough example and not full code...




mbernards -> RE: Printer IP replacement - Help needed (10/3/2008 11:41:38 AM)

prnadmin.dll from the Server 2003 ResKit can do that pretty easy.
the whitepaper doc is in there too.
 
RegSvr32.exe prnadmin.dll anf off you go.
I'm busy writing a Powershell PrinterFunctions.ps1 which you can include just like the Poweshell Community Extensions do.

The only problem I've got is it just won't register in Windows Vista SP1. (error 0x80020009)
I digged in with depends.exe to get an idea what's going on, and I think there are some functions missing in the includeset on which prnadmin.dll depends.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module
SHLWAPI and IEFRAME are marked red.

 
Anyone has a clue to fix this?
Is there a newer prnadmin.dll version available (2008 server?) or can the same be done with just plain old WMI?
 
 
Excerpt from the whitepaper:
 
---8<----
 
dim oPort
dim oMaster
 
‘Create the Port object.
set oPort = CreateObject("Port.Port.1")
 
‘Create the PrintMaster object.
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
 
‘Get the current configuration. The first argument is a server name; "" indicates local computer. The second
‘one is a port name; the third argument is a Port object, which will receive the settings of the specified port.

oMaster.PortGet "\\server", "IP_1.2.3.4", oPort
 
‘Set the new type: 1 (RAW) or 2 (LPR). An Err object may be used here to test the result of the get
'operation.

oPort.PortType = kTcpRaw
 
‘Set the address of the device to which it connects.
oPort.HostAddress = "2.3.4.5"
 
‘This applies to RAW ports only.
oPort.PortNumber = 9100
 
‘This applies to LPR ports only.
oPort.QueueName = "Queue"
 
‘Enable/disable SNMP.
oPort.SNMP = true
 
‘This applies if SNMP is enabled, SNMP device index.
oPort.SNMPDeviceIndex = 1
 
‘This applies if SNMP is enabled, SNMP community name.
oPort.CommunityName = "public"
 
Enable/disable byte counting (double spool).
oPort.DoubleSpool = true / false
 
‘Try updating the data.
oMaster.PortSet oPort
 
‘Error handling.
if Err <> 0 then
 
‘An error occurred
End if
 
 




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.203125