Scripts Thread, Help with Backup Script in Coding and Web Development; Trying to do an automatic backup when USB drive is plugged in, I'm using autorun to call the script but ...
-
12th June 2008, 06:10 PM #1
- Rep Power
- 0
Help with Backup Script
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
-
-
IDG Tech News
-
12th June 2008, 07:29 PM #2 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?
-
-
12th June 2008, 07:45 PM #3
- Rep Power
- 0
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

Originally Posted by
penfold_99
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?
Last edited by soze; 12th June 2008 at 07:47 PM.
-
-
12th June 2008, 08:47 PM #4 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:
Code:
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
-
-
13th June 2008, 06:30 PM #5
- Rep Power
- 0
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,

Originally Posted by
srochford
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:
Code:
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
-
-
18th June 2008, 12:12 AM #6 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.
-
SHARE:
Similar Threads
-
By mullet_man in forum MIS Systems
Replies: 13
Last Post: 23rd November 2007, 07:03 PM
-
Replies: 2
Last Post: 14th November 2007, 10:59 AM
-
By SimpleSi in forum Scripts
Replies: 9
Last Post: 18th January 2007, 03:45 PM
-
Replies: 1
Last Post: 30th April 2006, 08:02 PM
-
By ChrisH in forum Scripts
Replies: 12
Last Post: 20th October 2005, 01:01 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules