Created
January 9, 2019 16:54
-
-
Save tmontney/58bab43ecbabc7457057474762c0c052 to your computer and use it in GitHub Desktop.
Monitoring USB drive insertion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub weq_DeviceInsertion(sender As Object, e As EventArrivedEventArgs) | |
Dim LogDisk = e.NewEvent("TargetInstance") | |
Console.WriteLine(LogDisk.Properties("Name").Value) | |
End Sub | |
Private Sub AddWatcher() | |
'Copy weq_Insertion but use __InstanceDeletionEvent instead for Removals | |
Dim weq_Insertion As WqlEventQuery = New WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_LogicalDisk'") | |
w_Insertion = New ManagementEventWatcher(weq_Insertion) | |
AddHandler w_Insertion.EventArrived, AddressOf weq_DeviceInsertion | |
w_Insertion.Start() | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment