So I'm trying to make a bat file run automatically on Windows 10 to backup files to an external USB drive whenever the USB drive is plugged in. I've so far thought about doing a Windows Task Scheduler task, but as far as I know, Task Scheduler does not give the option to run a task when a specific device is attached to the computer (though if it does, please let me know and please also tell me how to do it as that would solve all the problems I'm having). I've also thought about doing this with an Autorun.inf, but Windows no longer supports that. So in lieu of either of those options, what is the best way to run a bat file for backup purposes when a specific USB drive is plugged in? P.S. Both for verification purposes that this is what I intend to do and if anyone needs to see it as a reference, below is a copy of the bat file I'm using for backup;
TITLE Backup of All Files (Excluding System Files) on the Main Drive C:
powershell -window minimized -command ""
@ECHO OFF
set dt=%DATE:~0,2%/%DATE:~3,2%/%DATE:~6,4%:%TIME:~0,2%.%TIME:~3,2%.
%TIME:~6,2%
set dt=%dt: =0%
ECHO %dt%>>backuplog-C.txt
robocopy C: %~dp0\C-MainDrive\ALL * /R:10 /E /W:15 /FFT /COPYALL /COPY:DAT /Z /TS /FP /XA:R /XD Temp Drivers "Program Files" "Program Files (x86)" found.000 found.001 found.002 msdownload.tmp Windows.old $WINDOWS.~WS $WinREAgent Documents and Settings $WINDOWS.~BT $Windows $GetCurrent $SysReset "#Windows" $RECYCLE.BIN "#RECYCLE BIN" "Documents and Settings" "System Volume Information" /XF hiberfil.sys pagefile.sys swapfile.sys /V
echo Backup completed at %dt%
robocopy Backup_Logs\ Backup_Logs\ >>Backup_Logs\backuplog_MainDrive.txt
powershell -Command "& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('The backup of all your files on your Main Drive C: drive has completed successfully.', 'Backup Successful!', 'OK', [System.Windows.Forms.MessageBoxIcon]::Information);}"