Trying to do an automatic backup when USB drive is plugged in, I'm using autorun to call the script but it doesn't seem to working.
Option Explicit
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell: Set objShell = CreateObject("Wscript.Shell")
Dim colDrives: Set colDrives = objFSO.Drives
Dim drive
Dim drvbackup
Dim errReturn
For each drive in colDrives
If objFSO.FileExists(drive & "\Autobackup.cmd") Then
If Instr(1,drive,":\",1)>0 Then
drvBackup = drive
Exit For
ElseIf Instr(1,drive,":",1)>0 Then
drvBackup = drive & "\"
Exit For
Else
drvBackup = drive & ":\"
Exit For
End If
End If
Next
If drvBackup = "" Then
msgbox "Cannot locate Autobackup.cmd on any of the drives attached to this computer"
wscript.quit 3
Else
errReturn = objShell.Run("robocopy.exe C:\ " & drvBackup & "BackupFolder /E /V /NP /ZB /R:3 /W:1",1,1)
If errReturn <> 0 Then
msgbox "Backup completed with the following error: " & errReturn
Else
msgbox "Backup completed successfully!"
End If
End If
wscript.quit 0