Novell Home

Scripts to Migrate Default Printer and iPrinter Settings to New Computer

Novell Cool Solutions: Feature
By Adam Reno

Digg This - Slashdot This

Posted: 15 Sep 2005
 

problem:

Would like to migrate all the iPrint Printers, Default Printer and LPT Port Captures from a user's old computer to their new computer.

(Could also use this to push printers out via the NAL too! - without using the iPrint policy)

solution:

I'd like to offer up these two vbscripts I've created...

The first, "Save iPrint.vbs" saves the printers, default printer setting, and all the lpt port captures to a text file of your choosing.

The second, "Restore iPrint.vbs" restores everything back from the text file the first script created. Uses iprntcmd.exe and icapture.exe to add and capture printers / ports.

--- Usage ---

Create two new text files named "Save iPrint.vbs" and "Restore iPrint.vbs" Copy and paste the proper script inside each one.

Inside each file, edit the "SAVEPATH" variable to point to where you'd like the file saved.

Run the "Save iPrint.vbs" to save the printers, then on the other computer, run the restore.vbs.

--- Zen Idea ---

I suppose if you save a "configuration" to the text file, you could NAL out the vbs script to whoever you want and force this printer config down to a group of users.

Enjoy!

Adam

save iprint.vbs

--------- 8< -(Save iPrint.VBS)- >8 -----------
'----Change this to where you want the file saved----
SAVEPATH = "H:\printers.txt"

On Error Resume Next
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WSHShell = CreateObject("WScript.Shell")
Set oPrinters = WshNetwork.EnumPrinterConnections

'----Get Default Printer----
DPRINTER = WSHShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")

'-----Format Default Printer------
LDP = Left(DPRINTER, 2)
RDP = Right(DPRINTER, 15)
DPRINTER = Replace(DPRINTER, LDP, "")
DPRINTER = Replace(DPRINTER, RDP, "")
DPRINTER = Replace(DPRINTER, "\", "/ipp/")
'wscript.echo DPRINTER



'-------Text File Writing Stuff-------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(SAVEPATH, True)

For i = 0 to oPrinters.Count - 1 Step 2
	if left(oPrinters.Item(i), 3) = "ipp" then
		if not oPrinters.Item(i) = DPRINTER then
		   objTextFile.WriteLine oPrinters.Item(i)
		   'WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
		end if
	end if
	Next

objTextFile.WriteLine "DEFAULT - " & DPRINTER

'----Search for LPT Ports-----
LPT1 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT1\Printer")
LPT2 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT2\Printer")
LPT3 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT3\Printer")
LPT4 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT4\Printer")
LPT5 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT5\Printer")
LPT6 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT6\Printer")
LPT7 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT7\Printer")
LPT8 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT8\Printer")
LPT9 = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Novell-iPrint\nipplpt\Ports\LPT9\Printer")

'----Write out only those keys that are not blank----
if not LPT1 = "" then objTextFile.WriteLine "LPT1 - " & LPT1
if not LPT2 = "" then objTextFile.WriteLine "LPT2 - " & LPT2
if not LPT3 = "" then objTextFile.WriteLine "LPT3 - " & LPT3
if not LPT4 = "" then objTextFile.WriteLine "LPT4 - " & LPT4
if not LPT5 = "" then objTextFile.WriteLine "LPT5 - " & LPT5
if not LPT6 = "" then objTextFile.WriteLine "LPT6 - " & LPT6
if not LPT7 = "" then objTextFile.WriteLine "LPT7 - " & LPT7
if not LPT8 = "" then objTextFile.WriteLine "LPT8 - " & LPT8
if not LPT9 = "" then objTextFile.WriteLine "LPT9 - " & LPT9

wscript.echo "Printers Saved to " & SAVEPATH 
--------------- >8 --------------------

restore iprint.vbs

--------- 8< -(Restore iPrint.VBS)- >8 ---------
'---Change this to where you saved the printer file----
SAVEPATH = "H:\Printers.txt"

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WSHShell = CreateObject("WScript.Shell")
Dim FSO 
Set FSO = CreateObject("Scripting.FileSystemObject") 
Dim MyTextStream 

Set MyTextStream = FSO.OpenTextFile(SAVEPATH, 1, False) 
     Do While Not MyTextStream.AtEndOfStream = True 
	
	PRINTER = MyTextStream.Readline
        PRINTERPREFIX = Left(PRINTER, 3)

	SELECT CASE PRINTERPREFIX
		CASE "ipp"
			DOIT = wshshell.run("%windir%\system32\iprntcmd.exe " & PRINTER & " /ADD", 1, true)
		CASE "DEF"
			DPRINTER = Replace(PRINTER, "DEFAULT - ", "")
			DOITDEFAULT = wshshell.run("%windir%\system32\iprntcmd.exe " & DPRINTER & " /ADD /DEFAULT", 1, true)
		CASE "LPT"
			LPTPORT = left(PRINTER, 4)
			LPTPRINTER = REPLACE(PRINTER, LPTPORT & " - ", "")
			PLACE = instr(10, PRINTER, "\")
			LPTNAME = MID(PRINTER, PLACE+1)
			WINDOWSDIR = wshshell.ExpandEnvironmentStrings("%windir%")
			DOITLPTCAP = wshshell.run("%windir%\system32\icapture.exe " & LPTPORT & " P=" & LPTNAME, 1, true)
	END SELECT
     Loop 


'----kill the text steam----
     MyTextStream.Close 
     Set MyTextStream = Nothing 

Set FSO = Nothing

'Stop and Start the Spooler Service ---just a nice thing to do---
REBOOTSPOOLER = wshshell.run("net stop spooler", 1, true)
DOITDEFAULT = wshshell.run("net start spooler", 1, true)
------------------- >8 -----------------------

environment:

2000/XP
iPrint Client 4.05 and above (tested on 4.11)...might work on 3.12 didn't test it


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell