I found this script on http://network-blog.lan-secure.com/2008/03/usb-detection-using-wmi-script.html
strComputer = "." '(Any computer name or address)
Set wmi = GetObject("winmgmts:" & strComputer & "
ootcimv2")
Set wmiEvent = wmi.ExecNotificationQuery("select * from __InstanceOperationEvent within 1 where TargetInstance ISA 'Win32_PnPEntity' and TargetInstance.Description='USB Mass Storage Device'")
While True
Set usb = wmiEvent.NextEvent()
Select Case usb.Path_.Class
Case "__InstanceCreationEvent" WScript.Echo("USB device found")
Case "__InstanceDeletionEvent" WScript.Echo("USB device removed")
Case "__InstanceModificationEvent" WScript.Echo("USB device modified")
End Select
Wend
This script is next to what I need. It detects the insertion of a usb drive. How to modify it to find the drive letter of the usb drive? If I get the drive letter, then on insertion instead of echoing "USB device found" I will be able to run command line scanner of Avast Antivirus to automatically scan the drive on Insertion. Please guide!
See Question&Answers more detail:os