0

I'm looking for a way to monitor when a flashdrive (USB) Is connected to my pc (windows).

My first idea was to use System.IO.DriveInfo.GetDrives inside a Timer, and check for the new drives that appear, but maybe this could be too CPU demanded (I didn't do it yet)

Do you guys know if there's a better way to do this in Visual Basic 10 ?

Regards

distante
  • 6,438
  • 6
  • 48
  • 90

1 Answers1

0

Use:

<DllImport("user32.dll", SetLastError:=True)> _
Public Shared Function RegisterDeviceNotification( _
  ByVal IntPtr As IntPtr, ByVal NotificationFilter As IntPtr, _
  ByVal Flags As Int32) As IntPtr
End Function

To register to notification of USB insertion.

Ref: MSDN and an answer here

Community
  • 1
  • 1
Leon
  • 867
  • 7
  • 13
  • Thanks, I was able to use declare the function in Visual Basic 10 adding "Imports System.Runtime.InteropServices" in the top of my code, but I can't find any example of how to use it inside a windows form based project. – distante Nov 09 '13 at 00:31