Reputation: 21
Is it possible for a batch script on my local machine (e.g. in D:\ Batch files\1.bat
) to run after I insert or eject a USB drive?
Upvotes: 0
Views: 955
Reputation: 73576
Preliminaries:
Computer
icon, select Manage
, go to Services
,Windows Driver Foundation - User-mode Driver Framework
and make sure it's running and its Startup Type is set to Automatic
or Automatic (Delayed Start)
.Now go to Task Scheduler
:
MyCoolBatch on USB-connect
.On Triggers
tab add a new trigger:
On an event
in the first dropdown boxMicrosoft-Windows-DriverFrameworks-UserMode/Operational
in the Log dropdownDriverFrameworks-UserMode
in the Source2003
in the Event ID (this is USB connect event)On Actions
tab make a new action and select your batch file.
You can add a parameter like plugged
.
Repeat steps 1-3 with an Event ID 2100
(the USB disconnect event) and a batch file parameter like ejected
so, assuming the same batch file is used, you can check if device was connected/ejected:
if "%1"=="plugged" .........
if "%1"=="ejected" .........
Based on The Windows 7 Event Log and USB Device Tracking article.
Upvotes: 1