MusicMan_08
Новичок
- Сообщения
- 28
- Репутация
- 0
Добрый день, нашел в сети скрипт, который позволяет сделать бекап с вставленного USB, но у меня почему-то не запускается...
Может быть кто-нибудь знает, как допилить его - чтобы была возможность назвать директорию, куда будет происходить копирование?
Версия AutoIt: v3.3.10.2
Описание:
Примечания:
Может быть кто-нибудь знает, как допилить его - чтобы была возможность назвать директорию, куда будет происходить копирование?
Код:
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 = "STUFF"
;Get Initial List of Drives to Check Against
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, USB
; $WATCH = False, CDROM
If $WATCH = True Then
; New USB Drive Was Detected, Time to Find it's Letter
$New = FindNewDrive(); $New now has the Drive Letter of our New Drive, so USE IT!!!
$Label = DriveGetLabel($New)
If $Label == $MyDrive Then
MsgBox(4096, "Info", "My Drive has been Inserted, Backup My Files!")
EndIf
; Now Reset Drive List so more insertions can also be detected accurately
UpdateDrives()
EndIf
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( "REMOVABLE" )
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
; 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
Версия AutoIt: v3.3.10.2
Описание:
Примечания: