Jump to content
Sign in to follow this  
Kovacic

Network printer backup and restore

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( ͡° ͜ʖ ͡°)

Share this post


Link to post
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.


Share this post


Link to post
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( ͡° ͜ʖ ͡°)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By tarretarretarre
      Version 2.x.x and 3.x.x has been moved to branch 3.x
      About Autoit-Socket-IO
      Autoit-Socket-IO is a event driven TCP/IP wrapper heavily inspired from Socket.IO with focus on user friendliness and long term sustainability.
      I constantly want to make this UDF faster and better, so if you have any suggestions or questions (beginner and advanced) Do not hesitate to ask them, I will gladly help!
      Key features
      Simple API 99% data-type serialization thanks to Autoit-Serialize Can easily be extended with your own functionality thanks to Autoit-Events "Educational" examples Data encryption thanks to _<Crypt.au3> Limitations
      Speed. This UDF will sacrifice some speed for convenience Read more in the official thread
    • By TXTechie
      Hello Everyone,
      I've developed my own GUI using AutoIt and I'm allowing users to minimize the GUI, but I also want to include some kind of timer so that it will automatically restore the GUI after something like 30 minutes or an hour. However, I also want them to be able to manually restore the GUI by clicking the application's icon in the taskbar.
      I've searched through the forums, but I'm not sure how to get started.
      Any ideas or functions to research are appreciated!
      Regards,
      TX Techie
    • By Jahar
      Hi All,
      Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.
    • By Exit
      Have you ever shut down the computer while still performing a backup? 
      If not, then ignore this post.

      Otherwise, this program may be helpful.
      It is registered in the startup folder after a query and then runs with every system start and ends only with system shutdown.
      Whenever a backup activity begins or ends, a message is generated.
      This prevents the computer from being accidentally turned off while a backup is still active.
      ; BackupDetector.exe Backup attention popup. ;============================================================================================================== ; Programm Name: BackupDetector.exe ; Description: Monitoring backup activities. ; Whenever a backup activity starts or ends, a message is generated. ; This eliminates the possibility of accidentally turning off the computer while a backup is still active. ; Syntax: BackupDetector.exe (no Parameters) ; Return Value(s): None. It's a never ending programm. ; Author: Exit ( http://www.autoitscript.com/forum/user/45639-exit ) ; SourceCode: http://www.autoitscript.com/forum/index.php?showtopic=199161 Version: 2019.06.21 ; COPYLEFT: © 2019 Freeware by "Exit" ; ALL WRONGS RESERVED ;============================================================================================================== #pragma compile(AutoItExecuteAllowed, True) #AutoIt3Wrapper_Res_SaveSource=y #NoTrayIcon If Not @Compiled Then Opt("TrayIconHide", 0) Opt("ExpandVarStrings", 1) #include <_SingleScript.au3> ; http://www.autoitscript.com/forum/index.php?showtopic=178681 _SingleScript() ; Close all running scripts with the same name $l = (StringRight(@OSLang, 2) = "07") ? 0 : 1 ; German=0 other=1 $sScriptShortcut = @AppDataDir & "\Microsoft\Windows\Start Menu\Programs\Startup\" & StringTrimRight(@ScriptName, 3) & "lnk" If @Compiled Then If Not FileExists($sScriptShortcut) Then $rc = MsgBox(4 + 32 + 256 + 262144, Default, $l ? _ "Should the program run at every system start?" : _ "Soll das Programm bei jedem Systemstart ausgeführt werden?") If $rc = 6 Then $rc = FileCreateShortcut(@ScriptFullPath, $sScriptShortcut) MsgBox(64 + 262144, Default, ($rc ? "" : ("--> " & ($l ? "NO" : "KEINE") & " <-- ")) & _ ($l ? "Shortcut created in the startup folder." : "Verknüpfung im Startordner erstellt.")) EndIf EndIf EndIf $bMessagebox = False $hPid = 0 While Sleep(5000) If ProcessExists("vssvc.exe") Then ; is Volume Shadow Copy running? If $bMessagebox = False Then If $hPid Then ProcessClose($hPid) $sText = $l ? "The backup is now running. @HOUR@:@MIN@:@SEC@@LF@" & _ "Please do not turn off the computer." & @LF & _ "When the backup is finished, a new message appears." : _ "Die Sicherung läuft jetzt. @HOUR@:@MIN@:@SEC@@LF@" & _ "Den Computer bitte nicht ausschalten." & @LF & _ "Wenn die Sicherung beendet ist, erscheint eine neue Meldung." $sCommand = '$rc = MsgBox(64+262144,@ScriptName & " on " & @Computername,"' & $sText & '") + Sleep(2147483647)' ; Retain PID due to sleep $sCommand = '"' & StringReplace($sCommand, '"', '""') & '"' $hPid = ShellExecute(@AutoItExe, ' /AutoIt3ExecuteLine ' & $sCommand) $bMessagebox = True EndIf Else If $bMessagebox = True Then If $hPid Then ProcessClose($hPid) $sText = $l ? "The backup is done. @HOUR@:@MIN@:@SEC@@LF@" & _ "The computer can (but does not have to) be turned off." & @LF & _ "Thank you for your patience, now you can press 'OK'." : _ "Die Sicherung ist fertig. @HOUR@:@MIN@:@SEC@@LF@" & _ "Der Computer kann (aber muss nicht) ausgeschaltet werden." & @LF & _ "Vielen Dank für ihre Geduld. Nun können Sie 'OK' drücken." $sCommand = '$rc = MsgBox(64+262144,@ScriptName & " on " & @Computername,"' & $sText & '") + Sleep(2147483647)' ; Retain PID due to sleep $sCommand = '"' & StringReplace($sCommand, '"', '""') & '"' $hPid = ShellExecute(@AutoItExe, ' /AutoIt3ExecuteLine ' & $sCommand) $bMessagebox = False EndIf EndIf WEnd ; End of BackupDetector script  
    • By rudi
      Hello,
      the following script is running quite nicely for a friend of mine doing a year of work and travel to have a backup at home for all the pics and movies taken with her mobile phone,
       
      The facts:
       
      At home: a VMWARE virtual machine with dropbox installed for her DB account
      On-the-Road: One mobile phone, Camera Uploads are activated for her dropbox account, one Laptop.
       
       
      The idea is to have a copy of *ALL* pictures and movies taken with the mobile phone *OUTSIDE* the dropbox folder, so that the DB Max Size is never exceeded.
      The script is running at home and doing this:
      Copy all content from the "Camera Upload Folder" within the dropbox folder to some folder *OUTSIDE* the DB folder Move all content from the "Camera Upload Folder" do some other folder *INSIDE* the DB folder to indicate, that the backup copies at home were done successfully  
      Dropbox is also installed on the Laptop she has with her. So on the Laptop she checks from time to time the destination folder inside the dropbox folder and moves the pics / movies on the laptop to some other folder outside the dropbox as well. By that final step the images are moved out of the dropbox on the mobile phone as well, so that there is always space left to sync more pics / movies.
       
      As moving pics / movies out of the dropbox folder on the laptop doesn't touch the copies in the mobile phone's "Gallery", she has all the pics / movies at all three locations:
      Mobile Phone Laptop VM at home  
      The folder names propably are different for non-German localized Windows and Dropbox, just modify them to meet your localization.
      DBox-Sync.au3
×
×
  • Create New...