Task automation with Visual Basic Script

In case you want to automate some tasks, for example backing up a specific folder from your computer every time you plug in a specific USB-Stick.
All you need to do is to execute the following Visual Basic Script on your computer.
Place it in the Startup folder of Windows if you want it to run every time you login.
Script on your computer

Set Shell = CreateObject( "WScript.Shell" )
Set fso = CreateObject("Scripting.FileSystemObject")
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colME = oWMI.ExecNotificationQuery("Select * from Win32_VolumeChangeEvent")

' Name of the Volume we are after
strVolumeName = "BACKUPDISK"

' Watch for new Drives
Do
Set oLE = colME.NextEvent
If oLE.EventType = 2 Then
' New Drive arrived
Set d = fso.GetDrive(oLE.DriveName)

If d.VolumeName = strVolumeName Then
Shell.Run oLE.DriveName & "\backup.vbs"
End If
End If
Loop

The Script will check for the Drivename (here: „BACKUPDISK“) and if the Drive is found it will execute the BackupScript on the USB-Stick.

Script (backup.vbs) on the USB-Stick

' This Script must be on the USB-Drive in the root directory
Set Shell = CreateObject( "WScript.Shell" )
Set fso = CreateObject("Scripting.FileSystemObject")

' Get the Userprofiledirectory & Computername
strUP = Shell.ExpandEnvironmentStrings( "%USERPROFILE%" )
strCN = Shell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
strDRV = fso.GetDriveName(WScript.ScriptFullName)

' Create a subfolder on the USB-Drive if it doesn't exist
If Not(fso.FolderExists (strDRV & "\Backup\" & strCN)) Then
fso.CreateFolder strDRV & "\Backup\" & strCN
End If

' Backup the Data (Overwrite existing files)
fso.CopyFolder strUP & "\Pictures", strDRV & "\Backup\" & strCN & "\", vbTrue

In this case all your pictures from the Picturefolder in your Userprofile are backed up.