0% found this document useful (0 votes)
82 views2 pages

AutoMountRemoveUSB Drive

This document provides instructions for automatically connecting and disconnecting an external USB drive before and after backups using VBS scripts. It describes: 1) Creating three VBS scripts (GetMountvol, MountUSBdisk, RemoveUSBdisk) to get the drive letter, mount the drive, and remove the drive. 2) Creating an Acronis backup task to write to the external USB drive. 3) Configuring the backup task to run the MountUSBdisk script before backups and RemoveUSBdisk script after backups using the Pre/Post Commands options.

Uploaded by

DiegoPepeus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views2 pages

AutoMountRemoveUSB Drive

This document provides instructions for automatically connecting and disconnecting an external USB drive before and after backups using VBS scripts. It describes: 1) Creating three VBS scripts (GetMountvol, MountUSBdisk, RemoveUSBdisk) to get the drive letter, mount the drive, and remove the drive. 2) Creating an Acronis backup task to write to the external USB drive. 3) Configuring the backup task to run the MountUSBdisk script before backups and RemoveUSBdisk script after backups using the Pre/Post Commands options.

Uploaded by

DiegoPepeus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

How to automatically connect / disconnect external USB drive before / after backup

1) Create three VBS scripts in NOTEPAD.exe with the following content.

GetMountvol.VBS

strDrive = InputBox("Please enter your USB drive letter"+vbCr+" example: L:", "USB
Drive Letter", "L:")
Dim f, f1
Set f=CreateObject("Scripting.FileSystemObject")
If f.DriveExists(strDrive) Then
dim oShell
Set oShell = CreateObject("WScript.Shell")
return = oShell.Run("cmd /c mountvol "+strDrive+" /L > mountvol.txt", 0, true)
Set f1 = f.OpenTextFile("mountvol.txt" ,8 , True)
f1.WriteLine(strDrive)
else
WScript.echo "Invalid Drive"
End If
WScript.quit

MountUSBdisk.VBS

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("mountvol.txt")
strGUID = trim(f.ReadLine)
strDrive = f.ReadLine
f.Close
Set fso= Nothing
intTimeout = 5 'Number of seconds to wait
strMessage = "USB disk drive mounted as "+strDrive
strTitle = "RescanUSBdisk"
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.Run "mountvol "+strDrive+" "+strGUID
intResult = oShell.Popup(strMessage, intTimeout, strTitle)
Wscript.Sleep 10*1000
WScript.quit

RemoveUSBdisk.vbs

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("mountvol.txt")
strGUID = trim(f.ReadLine)
strDrive = f.ReadLine
f.Close
Set fso= Nothing
intTimeout = 5 'Number of seconds to wait
strMessage = "USB disk device "+strDrive+" removed"
strTitle = "RemoveUSBdisk"
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.Run "mountvol "+strDrive+" /d"
intResult = oShell.Popup(strMessage, intTimeout, strTitle)
Wscript.Sleep 10*1000
WScript.quit

When saving the above scripts in Notepad, please ensure that they are saved as .VBS files, not as
default .TXT files. The three VBS files should be in the same folder.
Note: You can test the .VBS scripts by running these in an Administrator Command prompt window
using the full file name, i.e. GetMountvol.vbs / RemoveUSBdisk.vbs / MountUSBdisk.vbs

Important:
GetMountvol.vbs needs to be run in order to create a further ‘mountvol.txt’ file which is then used by
the two other VBS scripts to find the correct USB drive letter and Volume GUID information.
This script will prompt for the USB drive letter in the normal L: format.

Mountvol.txt will contain information that is similar to that shown below:

\\?\Volume{18000000-0000-0000-0000-100000000000}\
L:

The VBS scripts should be run with Administrator privileges.

2) Create your Acronis backup task which will write to your external USB drive.

Note: the task configuration needs to be completed while the USB drive is connected as otherwise
settings will be lost should the drive disconnect before these are completed.

3) Select the backup task Options, then open the Advanced settings page, then select Pre/Post
Commands then click on ‘Use custom commands’

Click on EDIT for the Post-Command and navigate to where the RemoveUSBdisk.vbs script is stored
and select this script. Use the option to Test the command and confirm that the script runs successfully.

Click on EDIT for the Pre-Command and navigate to where the MountUSBdisk.VBS script is stored
and select this script. Use the option to Test the command and confirm that the script runs successfully.

Click on OK when the above is done, then run the backup task.

You might also like