title: How to detect when a device has been connected/disconnected?
body: <p>I have tried the following:</p>
  
  <pre><code>Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
      Const WM_DEVICECHANGE As Integer = &amp;H219
      Const DBT_DEVICEARRIVAL As Integer = &amp;H8000
  
      If m.Msg = WM_DEVICECHANGE Then
        If m.LParam.ToInt32=DBT_DEVICEARRIVAL
          MessageBox.Show("Device arrival")
        End IF
      End If
  
      MyBase.WndProc(m)
  End Sub
  </code></pre>
  
  <p>But <code>m.LParam</code> constantly returns a value of <code>7</code> and hence I am unable to detect when a device is added. I am looking to allow my program to detect when a piece of hardware has been added and if it's a particular device then perform some action (I am not interested in USB mass storage devices so please don't send me any examples regarding this).</p>