I do not think that there is an entry in the Event logs at the time a USB is connected so I think your only hope would be to have a continually-running script that tests for that particular USB drive and triggers your main job when it is detected.
If you are interested in this idea then I have a script that tests for specific drives by name [i.e. label] and that could be readily modified to repeat itself every 10 seconds or whatever you decide on.
Batch file attached - GetDriveLetter-SubRoutine.bat
You'll probably have lots of questions. The start of the batch file provides answers to all the questions I could think of.
I use the batch file as a sub-routine within other scripts as, I believe, you will also want to.
It is called by Call :IdentifyDrive "%Drivelabel%" in which the variable %Drivelabel% is the label of the target drive.
It returns the variable %DriveLetter% for use by the main body of the script.
- Note the line beginning :: Pause If you delete the :: then you'll be able to watch the script progressing.
In your case, your script's main body would test for %DriveLetter% not being empty {which equals a variable not being defined} i.e. a drive has been identified which has the label sought for.
In your case, you would want to repeat that test for %DriveLetter% not being empty every 10 seconds [or whatever interval you want] using the TimeOut command e.g. TimeOut /T 10
so your main body would start with something like this [example drive labelled Fred, test repeats every 10 seconds]
Set Drivelabel=Fred
Set /a TestInterval=10
:RepeatedTesting
TimeOut /T %TestInterval%
Call :IdentifyDrive "%Drivelabel%"
:: If Defined DriveLetter ((Echo Yes, I found it) & Pause) Else ((Echo Stop messing about) & Pause)
If Defined DriveLetter (GoTo MainJobForThisUSB) Else (GoTo RepeatedTesting)
:IdentifyDrive
:: This is where you would copy in the code of GetDriveLetter-SubRoutine.bat
:: You'll need to remove the above place label :IdentifyDrive when you copy the batch file in. I just put it in here so this code block made sense on its own.
:MainJobForThisUSB
:: This is where you write in whatever the job is that you are trying to do with that USB drive
- The line beginning :: If Defined gives you a chance to monitor the work of the drive label identification by removing the ::
I suggest you test GetDriveLetter-SubRoutine.bat on its own first and then add it to your main script when you are confident in its behaviour.
I have tested GetDriveLetter-SubRoutine.bat extensively. I've been using it for a few years now.
I wrote out the rest of the code in this post just for you and have not tested it. But it's so simple that I don't believe that there are any flaws in it.
Denis