I am working on a application which should detect USB devices connected to the Computer. I got the following code after searching on the Internet:
Public Class Form1
Private Const WM_DEVICECHANGE As Integer = &H219
Private Const DBT_DEVICEARRIVAL As Integer = 32768
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DEVICECHANGE Then
If m.WParam = DBT_DEVICEARRIVAL Then
MessageBox.Show("Removable Drive Detected")
End If
End If
MyBase.WndProc(m)
End Sub
End Class
This code works fine for me.
But the problem is that if the USB device is connected first and the application is started afterwards, then it fails to detect the USB device.