Jump to content

Need Help with Optimizing working script


Tokolosh
 Share

Recommended Posts

Hi Guys

 

by Hacking around (Trial and Error)  with various Scripts and Snippets i have created this automatic "Backup to USB" Script with Emailing when successfull.
Currently i am using 2 Arrays for Source and Target Folders, which would probably be better to be able to put in 1 file. But at my current state this is a bit over my head.

So any Ideas on how to optimize it further are welcome.

#include <Misc.au3>
#Include<file.au3>
#include <Inet.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Opt("TrayAutoPause", 0)

If _Singleton(@ScriptName, 1) = 0 Then
    MsgBox($MB_SYSTEMMODAL, "Warning", "Only 1 Instance can be run at a time!")
    Exit
EndIf


If not fileexists(@ScriptName&".ini") then
    CreateIni()
endif

If not FileExists(@ScriptDir&"\SourceList.cfg") Then
    CreateSourceCfg()
EndIf

If not FileExists(@ScriptDir&"\TargetList.cfg") Then
    CreateTargetCfg()
EndIf

; Start Settings
Dim $DBT_DEVICEARRIVAL = "0x00008000"
Dim $DBT_DEVICECOMPLETEREMOVAL = "0x00008004"
Dim $USB_ATTENTION = "0x00000007"
Dim $WM_DEVICECHANGE = 0x0219
Dim $Drives
Dim $Drive_Type = "ALL"; Set to ALL because some USB Drives are detected as Fixed Disks, and we don't want to miss those
Dim $WATCH = False
Dim $MyDrive = IniRead(@ScriptName&".ini", "targetdevice", "targetname", "NotFound")
Dim $MyUSBDrive = IniRead(@ScriptName&".ini", "targetdevice", "targetname", "NotFound")
;Dim $backupfolder = IniRead(@ScriptName&".ini", "sourcefolder", "location", "NotFound")
Dim $backuptarget = IniRead(@ScriptName&".ini", "usbdisk", "targetfolder", "NotFound")
Dim $n
$SmtpServer = "smtp.gmail.com" ;IniRead(@ScriptName&".ini", "mailsettings", "smtpserver", "NotFound")              ; address for the smtp-server to use - REQUIRED
$FromName = IniRead(@ScriptName&".ini", "mailsettings", "vonname", "NotFound")                      ; name from who the email was sent
$FromAddress = "*******@*******.***" ;IniRead(@ScriptName&".ini", "mailsettings", "vonadresse", "NotFound") ; address from where the mail should come
$ToAddress = IniRead(@ScriptName&".ini", "mailsettings", "anadresse", "NotFound")   ; destination address of the email - REQUIRED
$Subject = "External Backup was successfull!"                   ; subject from the email - can be anything you want it to be
$Body = "Backup to " & $MyDrive & "\"& $backuptarget & " was processed successfully." ;& $backuptarget & " wurde erfolgreich ausgeführt."                              ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = ""                       ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
$CcAddress = ""       ; address for cc - leave blank if not needed
$BccAddress = ""     ; address for bcc - leave blank if not needed
$Importance = "Normal"                  ; Send message priority: "High", "Normal", "Low"
$Username = "*******@*******.***" ;IniRead(@ScriptName&".ini", "mailsettings", "mailuser", "NotFound")                    ; username for the account used from where the mail gets sent - REQUIRED
$Password = "*********" ;IniRead(@ScriptName&".ini", "mailsettings", "mailpasswort", "NotFound")                  ; password for the account used from where the mail gets sent - REQUIRED
$IPPort= "465" ;IniRead(@ScriptName&".ini", "mailsettings", "ipport", "NotFound")                          ; GMAIL port used for sending the mail
$ssl= "1"  ;IniRead(@ScriptName&".ini", "mailsettings", "ssl", "NotFound"); GMAILenables/disables secure socket layer sending - put to 1 if using httpS
$UseMail = IniRead(@ScriptName&".ini", "mailsettings", "aktiv", "NotFound")
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$Autostart=1
$StartupCommonDir = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"
; End Settings

If $Autostart=1 Then
$filename=StringRegExpReplace(@ScriptName, '(^.*).(.*)$', 'Automatic USB Backup')
If Not FileExists($StartupCommonDir&'\'&$filename&'.lnk') Then FileCreateShortcut ( @ScriptFullPath, $StartupCommonDir&'\'&$filename&'.lnk' )
EndIf

UpdateDrives()
;Setup The GUI to watch for the DeviceChange Event
GUICreate("")
GUIRegisterMsg($WM_DEVICECHANGE, "DeviceChange")
Func DeviceChange($hWndGUI, $MsgID, $WParam, $LParam)
Switch $WParam
Case $USB_ATTENTION
; This only happens when USB drives are inserted, so I use it to tell the difference between these and CDROMs
$WATCH = True
Case $DBT_DEVICECOMPLETEREMOVAL
; Whenever a Drive is Removed, Update the Drive List
UpdateDrives()
Case $DBT_DEVICEARRIVAL
; A drive was inserted
; Use $WATCH to tell if this was a CDROM or USB
; $WATCH = True, USBs
; $WATCH = False, CDROM
If $WATCH = True Then
; New USB Drive Was Detected, Time to Find it's Letter
    $New = FindNewDrive()
    $Label = DriveGetLabel($New)
    $MyDrive = $New
        If $Label = $MyUSBDrive Then
            If $UseMail = "1" then
                ;Backup2USB()
                SourceArray()
                MsgBox($MB_SYSTEMMODAL, "Success", "External Backup was successfull!", 5)
                SendMail()
            ElseIf $UseMail = "0" then
                ;Backup2USB()
                SourceArray()
                MsgBox($MB_SYSTEMMODAL, "Success", "External Backup was successfull!", 5)
            EndIf
        EndIf
EndIf
; Now Reset Drive List so more insertions can also be detected accurately
UpdateDrives()
EndSwitch
EndFunc;==>DeviceChange

; This just jumps through the new Drive List, comparing them until it finds the entry that is in the new one that isn't in the old one
Func FindNewDrive()
$Temp = DriveGetDrive( "ALL" )
For $i = 1 to $Temp[0]
$Old = False
For $j = 1 to $DRIVES[0]
If $DRIVES[$j] == $Temp[$i] Then $Old = True
Next
If $Old == False Then Return $Temp[$i]
Next
EndFunc;==>FindNewDrive

; Just to keep things neat, and so if Variables Ever Change, this makes updating easier
Func UpdateDrives()
$Drives = DriveGetDrive( $Drive_Type )
EndFunc;==>UpdateDrives


Func _DirCopyWithProgress($sFileSpec, $sDestDir, $nOverwrite)
   Local $sSourceDir
   Local $nSourceLen
   Local $sRootDir
   Local $hSearch
   Local $sFile
   Local $sPathList = "*"
   Local $sFileList
   Local $aCopyList
   Local $nTotalSize
   Local $nSize
   Local $i

   $i = StringInStr($sFileSpec, "\", 0, -1)
   $sSourceDir = StringLeft($sFileSpec, $i)
   $nSourceLen = StringLen($sSourceDir)

   $sFileSpec = StringRight($sFileSpec, StringLen($sFileSpec)-$i)

   If Not FileExists($sDestDir) Then
      If Not DirCreate($sDestDir) Then Return 0
   EndIf
   If StringRight($sDestDir, 1) <> "\" Then $sDestDir = $sDestDir & "\"

   $sRootDir = $sSourceDir
   While 1
      $hSearch = FileFindFirstFile($sRootDir & "*.*")
      If $hSearch > -1 Then
         $sFile = FileFindNextFile($hSearch)
         While Not @error
            If $sFile <> "." And $sFile <> ".." Then
               If StringInStr(FileGetAttrib($sRootDir & $sFile), "D") Then
                  $sPathList = $sPathList & $sRootDir & $sFile & "*"
               Else
                  If _MatchFilePattern($sFile, $sFileSpec) Then
                     $sFileList = $sFileList & StringTrimLeft($sRootDir, $nSourceLen) & "*" & $sFile & "*"
                     $i = FileGetSize($sRootDir & $sFile)
                     $nTotalSize = $nTotalSize + $i
                     $sFileList = $sFileList & $i & "*"
                  EndIf
               EndIf
            EndIf
            $sFile = FileFindNextFile($hSearch)
         Wend
         FileClose($hSearch)
      EndIf
      If $sPathList = "*" Then ExitLoop
      $sPathList = StringTrimLeft($sPathList, 1)
      $sRootDir = StringLeft($sPathList, StringInStr($sPathList, "*")-1) & "\"
      $sPathList = StringTrimLeft($sPathList, StringInStr($sPathList, "*")-1)
   Wend

   If $sFileList <> "" Then
      $aCopyList = StringSplit($sFileList, "*")
      For $i = 1 To $aCopyList[0]-2 Step 3
         If Not FileExists($sDestDir & $aCopyList[$i]) Then DirCreate($sDestDir & $aCopyList[$i])
         If FileCopy($sSourceDir & $aCopyList[$i] & $aCopyList[$i+1], _
                  $sDestDir & $aCopyList[$i] & $aCopyList[$i+1], $nOverwrite) Then
            $nSize = $nSize+$aCopyList[$i+2]
            ProgressSet(Int(($nSize/$nTotalSize)*100), $aCopyList[$i+1] & @CRLF & "Von: " & $aCopyList[$i])
         EndIf
      Next
   EndIf
   If $nSize = $nTotalSize Then
      Return 1
   Else
      Return 0
   EndIf
EndFunc

Func _MatchFilePattern($sFileName, $sPattern)
   Local $i
   Local $c
   Local $n
   Local $nMatch = 1

   For $i = 1 To StringLen($sPattern)
      $c = StringMid($sPattern, $i, 1)
      If $c <> "*" Then
         $n = StringInStr($sFileName, $c)
         If $n = 0 Then
            $nMatch = 0
            ExitLoop
         Else
            $sFileName = StringTrimLeft($sFileName, $n)
         EndIf
      EndIf
   Next
   Return $nMatch
EndFunc

GUICreate("")
GUIRegisterMsg($WM_DEVICECHANGE, "DeviceChange")
; Main Loop to Keep the Program Open
; No Real Way of ending this program, except for just killing the process
; Which is what I want, an always on backup for my drive every time I insert it
While 1
$GuiMsg = GUIGetMsg()
; This is needed because the watch event above not only triggers before a USB Drive is inserted/removed,
; but also AFTER insertion too, and if not reset, a subsequent CD insertion will trigger it again.
; So, every second, we reset $WATCH, to keep things clean
Sleep (1000)
$WATCH = False
WEnd

; The UDF
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
EndFunc   ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

Func SendMail()
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
EndIf
EndFunc

Func CreateIni()
    Local Const $sFilePath = @ScriptName&".ini"
    IniWrite($sFilePath, "targetdevice", "targetname", """Backupdisk""")
    IniWrite($sFilePath, "usbdisk", "targetfolder", """Backup""")
    IniWrite($sFilePath, "mailsettings", "aktiv", """0""")
    IniWrite($sFilePath, "mailsettings", "vonname", """External Backup""")
    IniWrite($sFilePath, "mailsettings", "anadresse", """recipient@mail.net""")
EndFunc

Func CreateSourceCfg()
    Local Const $sCfgPath = @ScriptDir &"\SourceList.cfg"
    FileWrite ( $sCfgPath, "D:\Testfolder\Subfolder" )
EndFunc

Func CreateTargetCfg()
    Local Const $sCfgPath = @ScriptDir &"\TargetList.cfg"
    FileWrite ( $sCfgPath, "Test" )
EndFunc

Func SourceArray()
    ; Read the current script file into an array using the filepath.
    Local $backupfolder = FileReadToArray(@ScriptDir &"\SourceList.cfg")
    Local $targetarray = FileReadToArray(@ScriptDir &"\TargetList.cfg")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
    Else
        For $i = 0 To UBound($backupfolder) - 1 ; Loop through the array.
            ProgressOn("External Backup has started", "", "Scanning Files . . .")
            $n = _DirCopyWithProgress($backupfolder[$i] & "\*", $MyDrive & "\"&$backuptarget&"\" & $targetarray[$i], 0)
            Sleep(2000)
            ProgressOff()
        Next
    EndIf
EndFunc

 

Edited by Tokolosh
Link to comment
Share on other sites

I made a USB backup script similar to yours.  The code below is constantly monitoring for the USB insertion or removal.  The first time you insert a USB the script create a new entry in the ini file using the USB's serial number as a section, then open the ini file to configure the folders and files that are going to be copy to the USB using numbers as a key and folders or files as a value EX:

[3021267457]
targetfolder="Backup"
1=C:\MyData
2=C:\MyDocuments\Test??.txt
3=C:\AutoitSourceCode\*.au3

 

#NoTrayIcon

$sFileIniPath = @ScriptName & '.ini'
$strComputer = "."

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colEvents = $objWMIService.ExecNotificationQuery _
        ("Select * From __InstanceOperationEvent Within 5 Where " _
         & "TargetInstance isa 'Win32_LogicalDisk'")

While 1
    $objEvent = $colEvents.NextEvent
    If $objEvent.TargetInstance.DriveType = 2 Or $objEvent.TargetInstance.DriveType = 3 Then
        $sDriveLetter = $objEvent.TargetInstance.DeviceId
        $sDriveLabel = $objEvent.TargetInstance.VolumeName
        $sDriveSerialNumber = DriveGetSerial($sDriveLetter)
        Select
            Case $objEvent.Path_.Class() = "__InstanceCreationEvent"
                $MyUSBDrive = IniRead($sFileIniPath, $sDriveSerialNumber, "targetfolder", "NotFound")
                If $MyUSBDrive = 'NotFound' Then
                    IniWrite($sFileIniPath, $sDriveSerialNumber, "targetfolder", """Backup""")
                    IniWrite($sFileIniPath, $sDriveSerialNumber, '1', 'C:\MyData') ; Copy the entire folder
                    IniWrite($sFileIniPath, $sDriveSerialNumber, '2', 'C:\MyDocuments\Test??.txt') ; Copy all Test?? files with the extension .txt
                    IniWrite($sFileIniPath, $sDriveSerialNumber, '3', 'C:\AutoitSourceCode\*.au3') ; Copy all the files with the extension .au3
                    ShellExecute($sFileIniPath, "", @ScriptDir, "open")
                Else
                    ; Here will be the code to read the ini file and start backing up the files
                EndIf
                ConsoleWrite('Drive = ' & $sDriveLetter & @CRLF & 'Label:' & $sDriveLabel & @CRLF & 'Serial: ' & $sDriveSerialNumber & @CRLF & @CRLF)

            Case $objEvent.Path_.Class() = "__InstanceDeletionEvent"
                ConsoleWrite('Drive = ' & $objEvent.TargetInstance.DeviceId & ' removed' & @CRLF & @CRLF)
        EndSelect
    EndIf
    Sleep(1000)
WEnd

 

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Hi Danny

Yeah our scripts are similar, thank you for showing me this. i will do some tests with it sometime over the weekend.
My one also constantly scans, just that i rely on the DiskName instead of Serial Number. The big problem i have is that i am using 2 arrays for SourceFolder to Target Names, which is so it is extendable when more folders are needed to be backed up.

For example:

SourceList.cfg (contains Fullpath to Sourcefolders for Backup)

C:\Some\TestDir
D:\Some\Other\Dir

TargetList.cfg (contains Foldername below the top backup folder)

TestDir
Dir

The idea i had was to combine them into 1 File to make it more "user friendly", i just have no idea on how to get it done.

What would be nice is to combine both files into something like:

BackupList.cfg

"C:\Some\TestDir" - "TestDir"              ("FullPath with or without spaces" - "TargetFolderName with or without spaces")

 

I have only begun to familiarize myself with RegEx, which i think could do the trick, but still have a long way to go.

Link to comment
Share on other sites

I use the USB serial number because the value can not be change.  This way I can always read the same ini section as a single array even if the DiskName change.  You can try to use RegEx, but I think it will be a lot easier if you try using IniReadSection() which it will give you a two dimension array with the source dir and usb target dir.  The code below may give you some ideas for your USB backup script and the ini file will look like:

[674332479]
DriveLetter=P:
C:\Temp\ManagePC=_My Backup\ManagePC
C:\Temp\Documents=_My Backup\Documents
C:\Temp\Pictures=_My Backup\Pictures
D:\Temp\Videos=_My Backup\Videos
E:\Temp\*.exe=_MyBackup\Temp
F:\Temp\*.iso=_MyBackup\Temp

 

Note:  

I'm using _Singleton() function in a different way.  The script called itself with /backup parameter to spawn a new process to start the backup in the inserted USB.   This way if I insert another USB the script is not waiting for the first USB to finish backing up, instead run another process and start backing up the files.

 

#NoTrayIcon

#include <Misc.au3>
#include <WinAPIFiles.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Local $MyUSBDrive = ''
Local $strComputer = "."
Global $sFileIniPath = StringTrimRight(@ScriptFullPath, 4) & '.ini'

If Not _Singleton('USBCopy', 1) and Not $CMDLine[0] Then
    MsgBox($MB_SYSTEMMODAL, "Warning", "Only 1 Instance can be run at a time!")
    Exit
ElseIf $CMDLine[0] >= 1 Then
    Switch $CMDLine[1]
        Case '/backup'
            If $CMDLine[0] <> 2 Then
                MsgBox($MB_SYSTEMMODAL, "Warning", "Wrong parameter(s) settings. It should have two patermeters with the USB serial number." & @CRLF & @CRLF & $CmdLineRaw)
            Else
                _UsbBackup($CMDLine[2])
            EndIf
        Case Else
            MsgBox($MB_SYSTEMMODAL, "Warning", "Unknown parameter(s)." & @CRLF & @CRLF & $CmdLineRaw)
    EndSwitch
    Exit
EndIf

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colEvents = $objWMIService.ExecNotificationQuery _
        ("Select * From __InstanceOperationEvent Within 5 Where " _
         & "TargetInstance isa 'Win32_LogicalDisk'")

While 1
    $objEvent = $colEvents.NextEvent
    If $objEvent.TargetInstance.DriveType = 2 Or $objEvent.TargetInstance.DriveType = 3 Then
        $sDriveLetter = $objEvent.TargetInstance.DeviceId
        $sDriveLabel = $objEvent.TargetInstance.VolumeName
        $sDriveSerialNumber = DriveGetSerial($sDriveLetter)
        Select
            Case $objEvent.Path_.Class() = "__InstanceCreationEvent"
                $MyUSBDrive = IniRead($sFileIniPath, $sDriveSerialNumber, "DriveLetter", "NotFound")
                If $MyUSBDrive = 'NotFound' Then
                    IniWrite($sFileIniPath, $sDriveSerialNumber, 'DriveLetter', $sDriveLetter)
                    IniWrite($sFileIniPath, $sDriveSerialNumber, 'SourceDir1', 'USB TargetDir') ; Copy the entire folder
                    IniWrite($sFileIniPath, $sDriveSerialNumber, 'SourceDir2', 'USB TargetDir') ; Copy all Test?? files with the extension .txt
                    IniWrite($sFileIniPath, $sDriveSerialNumber, 'SourceDir3', 'USB TargetDir') ; Copy all the files with the extension .au3
                    ShellExecuteWait($sFileIniPath, "", @ScriptDir, "open")
                ElseIf $MyUSBDrive <> $sDriveLetter Then
                    IniWrite($sFileIniPath, $sDriveSerialNumber, 'DriveLetter', $sDriveLetter)
                EndIf
                _RunIsCompiled('/backup ' & $sDriveSerialNumber)

            Case $objEvent.Path_.Class() = "__InstanceDeletionEvent"
                ConsoleWrite('Drive = ' & $objEvent.TargetInstance.DeviceId & ' removed' & @CRLF & @CRLF)
        EndSelect
    EndIf
    Sleep(250)
WEnd

Func _UsbBackup($sUsbSerialNumber)
    $sMyUSBDrive = IniRead($sFileIniPath, $sUsbSerialNumber, "DriveLetter", "NotFound")
    If $sMyUSBDrive = 'NotFound' Then Return(SetError(1, 1, 'Not drive letter found'))

    $aUSBBackupList = IniReadSection($sFileIniPath, $sUsbSerialNumber)
    If IsArray($aUSBBackupList) Then
        For $x = 1 To $aUSBBackupList[0][0]
            If StringInStr(FileGetAttrib($aUSBBackupList[$x][0]), 'D') Then
                DirCopy($aUSBBackupList[$x][0], $sMyUSBDrive & '\' & $aUSBBackupList[$x][1], 1)
            Else
                If StringRight($aUSBBackupList[$x][1], 1) <> '\' Then $aUSBBackupList[$x][1] &= '\' ;
                FileCopy($aUSBBackupList[$x][0], $sMyUSBDrive & '\' & $aUSBBackupList[$x][1], $FC_OVERWRITE + $FC_CREATEPATH)
            EndIf
        Next
    EndIf
EndFunc

Func _RunIsCompiled($sCommand)
    If Not @Compiled Then
        $iPID = Run(@AutoItExe & ' "' & @ScriptFullPath & '" ' & $sCommand, @ScriptDir)
    Else
        $iPID = Run(@AutoItExe & ' ' & $sCommand, @ScriptDir)
    EndIf
    Return($iPID)
EndFunc

 

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...