I have an Excel VBA application which sometimes needs to catch the event of removable drives adding (inserting in USB).
I found in MSDN a monitoring WMI script sample able to trigger the adding or removing event:
Trying to adapt it to VBA works only with Excel freezing (because of Do Loop cycle). I found code samples for VB.Net and VB6 but not for VBA.
Can anybody help on this issue?
Thanks in advance!
I found in MSDN a monitoring WMI script sample able to trigger the adding or removing event:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService. _
ExecNotificationQuery( _
"Select * from Win32_VolumeChangeEvent")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.DriveName
Wscript.Echo objLatestEvent.EventType
Wscript.Echo objLatestEvent.Time_Created
Loop
Can anybody help on this issue?
Thanks in advance!