Detect USB GPS Device Unplugged

NCSO
NCSO used Ask the Experts™
on
I have an application that tracks the position of vehicles within our agency and reports the decimal latitude and logitude back to our SQL Server.  I am experiencing issues with users unplugging their USB GPS device to prevent us from knowing their location.

I am looking for a method to detect when a user unplugs this device.  I can handle the reporting of the issue back to our servers, but I would greatly appreciate some assistance with the detection process.

Ps.  I have tried the following code and it works, partially!  It detects the insert and disconnect of any usb device, how can I modify this for the GPS only?


Many Thanks!

Imports System.Management

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Dim WithEvents w As ManagementEventWatcher
Dim q As WqlEventQuery

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

q = New WqlEventQuery("Select * from Win32_DeviceChangeEvent")
w = New ManagementEventWatcher(q)
w.Start()

End Sub

Private Sub w_EventArrived(ByVal sender As Object, ByVal e As System.Management.EventArrivedEventArgs) Handles w.EventArrived
MessageBox.Show("Device Event")
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
w.Stop()
End Sub

End Class

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I don't remember all the details, but you should be able to retrieve the info about what device was unplugged from System.Management.EventArrivedEventArgs.NewEvent object (a member of 2nd parameter in w_EventArrived handler)

it'll be some wmi query, so you should get some specific info and decide upon it

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial