rss logo

Do an action when a USB is plugged in

We will see here how to run a task as soon as a USB flash drive is plugged in.

I do it mainly to start antivirus scan on users machines.

Create a Windows Task

  • Type taskchd.msc inside a Run window :
Run taskschd.msc
  • Create a task :
Windows Task Scheduler create a task

Set parameters

  • Give a task name (ex : USB_scan), select user under who the task will be running (ex : SYSTEM) and hide the task.
Create a Task Window.
  • Create a new Action
Windows Task Scheduler set action.
  • Exemple here with Kaspersky Endpoint Security :
    • Program/script : "C:\Program Files (x86)\Kaspersky Lab\Kaspersky Endpoint Security for Windows\avp.exe"
    • Add arguments : SCAN /REMDRIVES
Windows Task Scheduler New action for kaspersky removable drives scan.
  • Now go to Triggers tab and click New... :
Windows Task Scheduler New trigger.
  • Set parameters :
    • Log : Microsoft-Windows-DeviceSetupManager/Admin
    • Source : DeviceSetupManager
    • Event ID : 112
Windows Task Scheduler New trigger for USB drives action.

Now, plug a USB flash drive and check that a scan is processing.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address