Jump to content

Network printer backup and restore


Kovacic
 Share

Recommended Posts

This is a very simple application to backup a list of your local and network printers to a shared resource.

when you restore the printers, the app will just install the printers that were networked. Feel free to improve upon and use.

Let me know what you think :)

I have many more applications and I may post more later.

#include <File.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $Backpath = "\\Myawesomeserver\useraccounts"
Global $fp = ($Backpath & @UserName)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Printer Tools", 334, 75, 192, 124)
$save = GUICtrlCreateButton("Save Printers", 8, 8, 155, 57)
$load = GUICtrlCreateButton("Load Printers", 168, 8, 155, 57)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $save
ExportPrinters()
Case $load
ImportPrinters()
EndSwitch
WEnd
Func ImportPrinters()
$File = $fp & "\NetworkPrinters.txt"
FileOpen($File, 0)
For $i = 1 to _FileCountLines($File)
$line = FileReadLine($File, $i)
RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /in /n " & $line, "", @SW_HIDE)
Next
FileClose($File)
Msgbox(0, "", "Network Printer Import Complete")
endfunc ;==>ImportPrinters
Func ExportPrinters()
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$Output = ""
$nOutput = ""
$objWMIService = ObjGet("winmgmts:\\" & @computername & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
For $objItem In $colItems
If Stringinstr($objItem.DeviceID, "\\") then
$nOutput = $nOutput & $objItem.DeviceID & @CRLF
else
$Output = $Output & $objItem.DeviceID & @CRLF
endif
Next
FileWrite($fp & "\NetworkPrinters.txt", $nOutput)
FileWrite($fp & "\LocalPrinters.txt", $Output)
Else
FileWrite($fp & "\Printers.txt", "No printers Found")
Endif
Msgbox(0, "", "Printer Export Complete")
EndFunc ;==>ExportPrinters

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

Not too shabby. Are you familiar with the PrintBRM tool?

It allows you to backup locally installed printers (drivers, queues and ports) to a archive like file for restoration.

Only included with Vista+ so it may not be the right solution for you, but it is a simple/effective tool that could be integrated into your script.

Link to comment
Share on other sites

That would be awesome! I was planning on making something like that to be part of a larger profile backup script. The difficult part is, we are backing up WinXP machines and moving to Windows 7.. So the drivers would be different. Unless I can install the same drivers under WinXP mode... That would be interesting to test.

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

  • 2 months later...

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
 Share

×
×
  • Create New...