|
-
Jan 15th, 2016, 01:33 PM
#1
Thread Starter
New Member
USB Detecter. Please Help
Hello! I have looked everywhere on google and youtube and other websites but have not seen any coding about how to detect if a USB gets disconnected. And now for my program i need that code, if you are good a visual basic 2010 and can help me please comment with a solution https://gyazo.com/06371278e308ae159b2e78528acffca4 Thanks!
-
Jan 15th, 2016, 02:08 PM
#2
Re: USB Detecter. Please Help
Windows raises events to tell you when a USB device is inserted and removed.
If you search for WM_DEVICECHANGE you should find many example, like,,
vb.net Code:
Public Class Form1 Private Const WM_DEVICECHANGE As Integer = &H219 Private Const DBT_DEVICEARRIVAL As Integer = &H8000 Private Const DBT_DEVICEREMOVECOMPLETE As Integer = &H8004 Private Const DBT_DEVTYP_VOLUME As Integer = &H2 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) 'check for the DEVICECHANGE message (Detects USB devices) If m.Msg = WM_DEVICECHANGE Then Select Case m.WParam.ToInt32 ' if a device was added or removed then update usb drives list. Case DBT_DEVICEARRIVAL, DBT_DEVICEREMOVECOMPLETE Dim DevType As Integer = Marshal.ReadInt32(m.LParam, 4) If DevType = DBT_DEVTYP_VOLUME Then ' DO SOMETHING... ' Me.BeginInvoke(New Action(AddressOf GetPenDrives)) End If End Select End If MyBase.WndProc(m) End Sub End Class
VB10 Test project, ripped and slapped together from one of my apps.
Attachment 134285
EDIT, Updated Zip , includes the ownerdrawn combobox as shown in image above.
Last edited by Edgemeal; Jan 15th, 2016 at 03:28 PM.
Reason: update file again!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|