soze Posted June 12, 2008 Posted June 12, 2008 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
penfold_99 Posted June 12, 2008 Posted June 12, 2008 hi, I'm trying to follow what your trying to do, but i think your going about it a bit backwards. You can find out was the driver letter the script is being run from using this. drive = objFSO.GetDriveName(Wscript.ScriptFullName) The instead of shelling out to robo copy, you can use objFSO.CopyFolder locationA locationB is the script running or erroring out?
soze Posted June 12, 2008 Author Posted June 12, 2008 (edited) I'm trying to run an automatic backup, I have a external USB drive that has an autorun file that calls this script. I'm trying to copy the entire C:\ to the USB drive to a folder named, Backup Folder It errors out, Line 29 Char. 5 hi, I'm trying to follow what your trying to do, but i think your going about it a bit backwards. You can find out was the driver letter the script is being run from using this. drive = objFSO.GetDriveName(Wscript.ScriptFullName) The instead of shelling out to robo copy, you can use objFSO.CopyFolder locationA locationB is the script running or erroring out? Edited June 12, 2008 by soze
srochford Posted June 12, 2008 Posted June 12, 2008 There's a lot of checking which I don't understand and just makes the logic harder to follow but I think you may have too many endifs :-) this works to find the drive letter: For each drive in colDrives If objFSO.FileExists(drive.driveLetter & ":\Autobackup.cmd") Then drvBackup=drive.driveLetter exit for end if Next and the rest of the code seems fine
soze Posted June 13, 2008 Author Posted June 13, 2008 Thanks, I'm going to test it out. This was for a automatic backup of a external USB drive. I needed it to start backing up as soon as the drive is plugged in. I needed it to find the next available drive letter. I had made a small robocopy file but you have to assign a drive letter to the destination folder, only thing every user has different drive mappings so I needed the script to assign the drive letter and start the copy using the robocopy cmd. Thx again, There's a lot of checking which I don't understand and just makes the logic harder to follow but I think you may have too many endifs :-) this works to find the drive letter: For each drive in colDrives If objFSO.FileExists(drive.driveLetter & ":\Autobackup.cmd") Then drvBackup=drive.driveLetter exit for end if Next and the rest of the code seems fine
Arthur Posted June 17, 2008 Posted June 17, 2008 Using a program like USB Detect and Launch might make it a bit easier since your script would just need to do the backup then.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now