Skip to content

Instantly share code, notes, and snippets.

@tmontney
tmontney / usbmonitoring.vb
Created January 9, 2019 16:54
Monitoring USB drive insertion
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
@tmontney
tmontney / Form1.vb
Created August 9, 2017 03:01
On send, route is still processed; error in BeforeRouting sends exception text
Public Class Form1
Dim svr As Grapevine.Server.RestServer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
svr = New Grapevine.Server.RestServer
With svr
.Port = 80
.Host = "0.0.0.0"
.UseHttps = False
AddHandler svr.Router.BeforeRouting, AddressOf BeforeRouting
.LogToConsole.Start()
Private Sub Server_Close(sender As Object, e As EventArgs) Handles MyBase.Disposed
If svr IsNot Nothing AndAlso svr.IsListening Then svr.Stop()
End Sub