Sign in to follow this  
Followers 0
Steven Vandenhoute

backup printers and printerssettings

16 posts in this topic

Is it possible to backup all your printers (and printer settings)

This to easily reinstall all the printers after a format

(Oh ja, they are only network printers, so there are no problems with drivers)


"You cannot solve a problem with the mind that created it" (Albert Einstein)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

They are just some registry-entries somewhere under print/lanmanager/connections (?)...

Sorry, I messed arround with that a week ago, but I don't have the OS and my notes at hand, so please search for the name or IP of one of your printers and you'll be fine.

If you like to be 100%, have a look at regshot. It is free, small and can compare to "registry-states". 1st shot without, 2nd with printers "installed" > compare and you'll get the keys.

If you got them, you can just stop the spooler-service at any pc, add the registry-keys and restart the spooler > your printers are installed -- really neat. :whistle:

Edited by dabus

Share this post


Link to post
Share on other sites

thx for the type, I'll give it a try and get back to you when I found something


"You cannot solve a problem with the mind that created it" (Albert Einstein)

Share this post


Link to post
Share on other sites

I would like to know the answer for this issue aswell... If you find out anything, please let me know aswell... :whistle:


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

I've found all the installer printers under hkey_current_users\printers

now I'm looking for a way to export this so I can add it later on back


"You cannot solve a problem with the mind that created it" (Albert Einstein)

Share this post


Link to post
Share on other sites

Does somebody knows a way to export the registry key to *.reg with auto it?

Or another way to export this?

I use regread, but I can't get it to work (only for one line)


"You cannot solve a problem with the mind that created it" (Albert Einstein)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Here we go (got it from http://www.windowsnetworking.com/kbase/Win...eRegistry.html)

There is a problem with NT printer definitions that may cause you problems. You follow standard advice to uninstall and reinstall the printer driver. Sometimes this doesn't fix the problem and you have no choice but to remove a printer. When you use the Remove or Delete Printer options in Print Manager, the printer connection disappears immediately. However, the spooler simply marks the printer for deletion. NT doesn't actually delete the printer until you reboot the system. Sometimes NT will delete the definition if you stop and restart the spooler. Sometimes it doesn't. If this doesn't work, and you will find out when you try to redefine the printer. No issue for workstations. You can reboot. Unfortunately there are servers which can not be rebooted (or at least not for something like a printer definition). For servers which can not be rebooted, you can remove the printer definition from the registry by hand prior to the reinstall.

If it is a local printer (My Computer), go to the following registry keys and delete the respective entries:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\ Windows NT x86\ Drivers\Version-2\

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\

If it is a network printer (network printer server or \\), go to the following registry keys and delete the respective and entries:

HKEY_CURRENT_USER\Printers\Connections\

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Providers\ LanMan Print Services\Servers\\Printers\

After the registry edit, you need to stop and restart the spooler service. At this point, you'll be able to reinstall the printer driver correctly.

----

I hope you don't mind I lost that damn lanman-key :whistle:...

I use to export the keys with regedt32 and run them... shouldn't be that tough. Plus, you can use the reg-files if autoit got delete by an antivirus-installation ;D At last it's easier than converting them to autoit-code.

Edited by dabus

Share this post


Link to post
Share on other sites

Heres a script I use to sync the printers on 2 servers...

It only syncs printers that have an Port attached that is using "IP_*"as port.

This should help you to get started :whistle:

;Sync all ports and Printers from ServerA to ServerB
;Read header record
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler
;$strFromComputer = "."
$strFromComputer = "ServerA"
$strToComputer = "ServerB"
$objFromWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,(LoadDriver)}!\\" & $strFromComputer & "\root\cimv2")
$objToWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,(LoadDriver)}!\\" & $strToComputer & "\root\cimv2")
;======================================================================================
; List all IP Ports and Printers on serverA and create them on the serverB
$colInstalledPrinters = $objFromWMIService.ExecQuery ("Select * from Win32_Printer")
For $objFromPrinter In $colInstalledPrinters
    ;
    $OutRec = ""
    If StringLeft($objFromPrinter.PortName, 3) = "IP_" Then
        $colInstalledPorts = $objFromWMIService.ExecQuery ("Select * from Win32_TCPIPPrinterPort Where Name = '" & $objFromPrinter.PortName & "'")
        For $objFromPort In $colInstalledPorts
            $colInstalledPortsTo = $objToWMIService.ExecQuery ("Select * from Win32_TCPIPPrinterPort Where Name = '" & $objFromPrinter.PortName & "'")
            $PortFound = 0
            For $objToPort In $colInstalledPortsTo
                If $objToPort.Name = $objFromPort.Name Then $PortFound = 1
            Next
            If $PortFound = 0 Then
                ConsoleWrite("+> Create Port:" & $objFromPort.Name & "   Used by printer:" & $objFromPrinter.DeviceId & @LF)
                ; create same printerport and name on target
                $objToPort = $objToWMIService.Get ("Win32_TCPIPPrinterPort" ).SpawnInstance_
                $objToPort.Name = $objFromPort.Name
                $objToPort.Protocol = $objFromPort.Protocol
                $objToPort.ByteCount = $objFromPort.ByteCount
                $objToPort.HostAddress = $objFromPort.HostAddress
                $objToPort.Queue = $objFromPort.Queue
                $objToPort.PortNumber = $objFromPort.PortNumber
                $objToPort.SNMPCommunity = $objFromPort.SNMPCommunity
                $objToPort.SNMPEnabled = $objFromPort.SNMPEnabled
                 $objToPort.Put_
            Else
                ConsoleWrite("> Port already exists:" & $objFromPort.Name & @LF)
            EndIf
            $colInstalledToPrinters = $objToWMIService.ExecQuery ("Select * from Win32_Printer Where DeviceId = '" & $objFromPrinter.DeviceId & "'")
            $PrinterFound = 0
            For $objToPrinter In $colInstalledToPrinters
                If $objToPrinter.DeviceId = $objFromPrinter.DeviceId And $objToPrinter.PortName = $objFromPrinter.PortName Then
                    $PrinterFound = 1
                EndIf
            Next
            If $PortFound = 0 Then
                ConsoleWrite("+> Create Printer:" & $objFromPrinter.DeviceId & @LF)
                ; Create Printer
                $objToPrinter = $objToWMIService.Get ("Win32_Printer" ).SpawnInstance_
                $objToPrinter.DriverName = $objFromPrinter.DriverName
                $objToPrinter.PortName = $objFromPrinter.PortName
                $objToPrinter.DeviceId = $objFromPrinter.DeviceId
                $objToPrinter.Location = $objFromPrinter.Location
                $objToPrinter.Network = $objFromPrinter.Network
                $objToPrinter.Shared = $objFromPrinter.Shared
                $objToPrinter.ShareName = $objFromPrinter.ShareName
                 $objToPrinter.Put_
            Else
                ConsoleWrite("> Printer already exists:" & $objFromPrinter.DeviceId & @LF)
            EndIf
        Next
    Else
        $OutRec = "*******  "
        $OutRec = $OutRec & $objFromPrinter.DeviceId
        $OutRec = $OutRec & @TAB & $objFromPrinter.PortName
        $OutRec = $OutRec & @TAB & $objFromPrinter.Location
        ConsoleWrite("Skip: " & $OutRec & @LF)
        $OutRec = ""
    EndIf
Next

Exit

; This is my custom error handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
            "Line  is: " & $oMyError.scriptline & @CRLF & _
            "Number is: " & $oMyError.number & @CRLF & _
            "HexNumber is: " & $HexNumber & @CRLF & _
            "Description is: " & $oMyError.description & @CRLF & _
            "Source is: " & $oMyError.source & @CRLF & _
            "Windescription is: " & $oMyError.windescription)
    SetError(1) ; something to check for when this function returns
EndFunc   ;==>MyErrFunc

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Damn, I could have had use for that one a week ago... ;)

I had to migrate all the files+shares and printers from one old nt4-server to a new 2003 one, little tricky if the old and new domain don't trust each other...

btw.: does that script work under that circumstances? My (silly) method does. :whistle:

Share this post


Link to post
Share on other sites

btw.: does that script work under that circumstances? My (silly) method does. :whistle:

Sure ... doesn't matter it its below 0 to above 30 Celcius .. it keeps on working ;)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Sure ... doesn't matter it its below 0 to above 30 Celcius .. it keeps on working :whistle:

I still have some probs to export a list of mapped printers.

Is there anybody who can help me with this.


"You cannot solve a problem with the mind that created it" (Albert Einstein)

Share this post


Link to post
Share on other sites

I still have some probs to export a list of mapped printers.

Is there anybody who can help me with this.

you should use the appropriate tools, instead of trying to do it yourself ;-)

http://www.microsoft.com/WindowsServer2003...igrator3.1.mspx

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

This is a printer install utility we use to install network printers. All you need to do to capture the printers is add a button that uses RUNDLL32 PRINTUI.DLL with the correct switches. Here are some links that should give you what you want:

http://support.microsoft.com/kb/314486/

www.robvanderwoude.com/2kprintcontrol.html

Here is the script:

#include <GuiConstants.au3>
#include <Process.au3>
#include <Array.au3>
$g_szVersion = "PrintInst.exe"
If WinExists($g_szVersion) Then Exit
Opt("TrayIconDebug", 1) ;debug is on

Dim $hService, _
        $data, _
        $sPrinter, _
        $sPrinterList, _
        $font = "Comic Sans MS", _
        $Input[12], $Combo[7], $radio[7], _
        $check[11], $Button[6]

Global Enum Step + 25 _
        $CON_POS_1 = 25, _
        $CON_POS_2, _
        $CON_POS_3, _
        $CON_POS_4, _
        $CON_POS_5, _
        $CON_POS_6, _
        $CON_POS_7, _
        $CON_POS_8, _
        $CON_POS_9, _
        $CON_POS_10, _
        $CON_POS_11

GUICreate("", 600, 290, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GUICtrlCreateLabel("\\", 20, 54, 10, 20)
$iniread_1 = IniRead(@ScriptDir & "/npu.ini", "SERVER", "SERVER", "")
$iniread_2 = IniRead(@ScriptDir & "/npu.ini", "Printers", "PLIST", "")
iniwrite(@ScriptDir & "/npu.ini", "Printers", "LOCAL", "")
$iniread_3 = IniRead(@ScriptDir & "/npu.ini", "Printers", "LOCAL", "")
$LocalPrinters = StringSplit($iniread_3, "|")
If $LocalPrinters[0] > 10 Then
    ReDim $LocalPrinters[11]
EndIf

$Input[1] = GUICtrlCreateInput($iniread_1, 35, 50, 100, 20)

For $i = 2 To 11
    $Input[$i] = GUICtrlCreateInput("", 270, Eval("CON_POS_" & $i - 1), 270, 21)
    If ($i - 1) <= $LocalPrinters[0]Then
        GUICtrlSetData(-1, $LocalPrinters[$i - 1])
    EndIf
Next

For $i = 1 To 6
    $Combo[$i] = GUICtrlCreateCombo("", 20, Eval("CON_POS_" & $i + 2), 170, 21)
    GUICtrlSetData(-1, $iniread_2)
    $radio[$i] = GUICtrlCreateRadio("", 210, Eval("CON_POS_" & $i + 2), 15, 21)
Next

For $i = 1 To 10
    $check[$i] = GUICtrlCreateCheckbox("", 550, Eval("CON_POS_" & $i), 20, 20)
Next

GUICtrlCreateLabel("Currently install printers", 270, 3, 200, 21)
GUICtrlCreateLabel("Delete", 550, 7, 100, 21)
GUICtrlCreateGroup("Default", 200, 62, 50, 160)

$Button[1] = GUICtrlCreateButton("Run", 20, 225, 35, 30)
$Button[2] = GUICtrlCreateButton("Exit", 65, 225, 35, 30)
$Button[3] = GUICtrlCreateButton("Find", 146, 50, 43, 20)
$Button[4] = GUICtrlCreateButton("Find", 498, 3, 43, 20)
$Button[5] = GUICtrlCreateButton("Restart Spooler", 110, 225, 80, 30)

$Label_1 = GUICtrlCreateLabel("   Network Printer Utility" & @CRLF & "for Windows Print Servers", 20, 0, 240, 50)
GUICtrlSetFont(-1, 10, 400, "", $font)
$Label_2 = GUICtrlCreateLabel("2006 CTS Scripting Team", 40, 270, 130, 25)
$_dummy = GUICtrlCreateDummy()

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button[1]
            _Rprinter()            
            _instprint()
            MsgBox(0, "", "Done!", 3)
        Case $Button[2]
            ExitLoop
        Case $Button[3]
            $data = GUICtrlRead($Input[1], 0)
            _netprint1()
        Case $Button[4]
            _getinstalledPrinters()
        Case $Button[5] 
            _restart()
        Case Else
            ;;;
    EndSwitch
WEnd

Exit

Func _netprint1()
    $hService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & "\\" & $data & "\root\cimv2")
    If @error Then
        MsgBox(48, "ERROR", "No Printers Found. Possible issues: " & @CRLF _
                 & "" & @CRLF _
                 & "  1. The Windows Print Server name has been entered in incorrectly." & @CRLF _
                 & "  2. You are trying to access a Novell Server. This utility does not support Novell Print Servers." & @CRLF _
                 & "  3. There are no printers shared on the Windows Print Server you selected.")
    Else
        _np2()
    EndIf
EndFunc   ;==>_netprint1

Func _np2()
    Local $i = 0
    Local $sPrinters = ""
    Local $aArray[1]
    
    SplashTextOn("", "Gathering printers, please wait...", 150, 75)
    
    For $y = 1 To 6
        GUICtrlSetData($Combo[$y], "")
    Next
    IniWrite(@ScriptDir & "/npu.ini", "Printers", "PLIST", "")
    
    $oPrinterList = $hService.ExecQuery ("Select * From Win32_Printer")
    
    For $oPrinter In $oPrinterList
        ReDim $aArray[$i + 1]
        $aArray[$i] = StringUpper($oPrinter.name)
        $i += 1
    Next
    
    _ArraySort($aArray)
    
    For $i = 0 To UBound($aArray)-1
        For $y = 1 To 6
            GUICtrlSetData($Combo[$y], $aArray[$i])
        Next
    Next
        
    $iElements = UBound($aArray) - 1
    For $x = 0 To $iElements
        If $x = $iElements Then
            $sPrinters &= $aArray[$x]
        Else
            $sPrinters &= $aArray[$x] & "|"
        EndIf
    Next
    
    IniWrite(@ScriptDir & "/npu.ini", "Printers", "PLIST", $sPrinters)
    $dataget2 = GUICtrlRead($Input[1], 0)
    IniWrite(@ScriptDir & "/npu.ini", "SERVER", "SERVER", $dataget2)
    SplashTextOn("", "Select what printers you wish to install", 150, 75)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>_np2

Func _instprint()
    Local $ComboGet[7], $RadioGet[7]
    
    SplashTextOn("", "Installing printer, please wait...", 150, 75)
    
    $InputGet = GUICtrlRead($Input[1], 0)
    
    For $i = 1 To 6
        $ComboGet[$i] = GUICtrlRead($Combo[$i], 0)
        $RadioGet[$i] = GUICtrlRead($radio[$i], 0)
    Next
    
    For $i = 1 To 6
        If $ComboGet[$i] <> "" Then             
            RunWait(@SystemDir & "\RUNDLL32 PRINTUI.DLL,PrintUIEntry /ga /c\\" & @ComputerName & " /n\\" & $InputGet & "\" & $ComboGet[$i])  
        EndIf
    Next
    _RunDOS("NET STOP spooler")
    _RunDOS("NET START spooler")
    sleep(10000)
    For $i = 1 To 6 
            If $RadioGet[$i] = 1 Then
                If $ComboGet[$i] <> "" Then
                RunWait(@SystemDir & "\RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n\\"&$iniread_1&"\"& $ComboGet[$i])
                endif
            EndIf   
            GUICtrlSetData($Combo[$i],"")
            GUICtrlSetState($radio[$i], $GUI_UNCHECKED)
            sleep(50)
            GUICtrlSetData($Combo[$i],$iniread_2)            
    Next
    SplashOff()
EndFunc   ;==>_instprint

func _restart()
    SplashTextOn("", "Stopping Print Spooler, please wait...", 150, 75)
    _RunDOS("NET STOP spooler")
    SplashOff()
    SplashTextOn("", "Starting Print Spooler, please wait...", 150, 75)
    _RunDOS("NET START spooler")
    SplashOff()
EndFunc 

Func _getinstalledPrinters()
    
    SplashTextOn("", "Gathering installed printers, please wait...", 200, 75)
    
    IniWrite(@ScriptDir & "/npu.ini", "Printers", "LOCAL", "")
    $hService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & "\\" & @ComputerName & "\root\cimv2")
    $sPrinterList = $hService.ExecQuery ("Select * From Win32_Printer")
    ConsoleWrite('$sPrinterList.count = ' & $sPrinterList.count & @LF)
    For $sPrinter In $sPrinterList
        ConsoleWrite('$sPrinter.name = ' & $sPrinter.name & @LF)
        $rd3 = IniRead(@ScriptDir & "/npu.ini", "Printers", "LOCAL", "")
        IniWrite(@ScriptDir & "/npu.ini", "Printers", "LOCAL", $rd3 & $sPrinter.name & "|")
    Next
    $local = StringSplit(IniRead(@ScriptDir & "/npu.ini", "Printers", "LOCAL", ""), "|")
    If UBound($local) < 11 Then ReDim $local[11]
    For $i = 1 To 10
        GUICtrlSetData($Input[$i + 1], $local[$i])
    Next
    
    SplashOff()
EndFunc   ;==>_getinstalledPrinters

Func _Rprinter()
    Local $InputGet[11]
    For $i = 2 To 11
        $InputGet[$i - 1] = GUICtrlRead($Input[$i])
    Next
    For $i = 1 To 10
        If GUICtrlRead($check[$i]) = 1 Then
            SplashTextOn("", "Removing printer, please wait...", 150, 50)
            GUICtrlSetState($check[$i], $GUI_UNCHECKED)
            sleep(1000)
            If $InputGet[$i] <> "" Then
                $str = StringLeft($InputGet[$i], 2)
                If $str = "\\" Then
                    RunWait(@SystemDir & "\RUNDLL32 PRINTUI.DLL,PrintUIEntry /gd /dn /n /c\\" & @ComputerName & " /n" & $InputGet[$i])
                    ;RunWait(@SystemDir & "\RUNDLL32 PRINTUI.DLL,PrintUIEntry /gd /q /c\\" & @ComputerName & " /n" & $InputGet[$i]) ;mine original
                    ;RunWait(@ComSpec & ' /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /gd /dn /q /n "' & $ret & '"', '', @SW_HIDE) ;danny35
                    GUICtrlSetData($InputGet[$i], "")
                Else
                    RunWait(@SystemDir & '\RUNDLL32 PRINTUI.DLL,PrintUIEntry /dl /q /n "' & $InputGet[$i] & '" /c\\' & @ComputerName)
                EndIf
            EndIf
        EndIf
    Next
    
EndFunc   ;==>_Rprinter

Share this post


Link to post
Share on other sites

I still have some probs to export a list of mapped printers.

Is there anybody who can help me with this.

Maybe some more info about the problem you are having ?

The example posted specifically tests for IP_ ports did you change that ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

;Store all printer settings into a file:

run('rundll32 printui.dll,PrintUIEntry /Ss /n "printer" /a "file.dat"')

;Restore all printer settings from a file:

run('rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat"')


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

I have run into this problem and in the end, I used a microsoft utility called Printmig.exe.

Upon restore, you can hide the window that printmig displays using @sw_hide.

printmig.exe solved all my problems regarding deploying uniform printer settings across the network.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0