adam_pedley
asked on
Detect USB Pen Drives
Hi
Is it possible in vb to detect any USB Pen drives attached to the computer?
Thanks
Adam
Is it possible in vb to detect any USB Pen drives attached to the computer?
Thanks
Adam
ASKER
Thanks
but how do i scan already existing drives to find a flash drive, i cant always depend that my program will be loaded before the flash drive is plugged in
but how do i scan already existing drives to find a flash drive, i cant always depend that my program will be loaded before the flash drive is plugged in
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is how you can get all the drives
http://www.csharphelp.com/archives2/archive363.html
http://www.csharphelp.com/archives2/archive363.html
ASKER
Thanks
Here is the final code I came up with that detects all drives and finds out what type they are
Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Integer
Private Sub Detect_Drives()
txtDrives.Clear()
Try
Dim str() As String = Directory.GetLogicalDrives ()
Dim i As Integer = 0
While i < str.Length
txtDrives.AppendText(str(i ) & " " & GetDriveType(str(i)) & vbCrLf)
i += 1
End While
Catch ex As IOException
MsgBox(ex.Message)
End Try
End Sub
Here is the final code I came up with that detects all drives and finds out what type they are
Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Integer
Private Sub Detect_Drives()
txtDrives.Clear()
Try
Dim str() As String = Directory.GetLogicalDrives
Dim i As Integer = 0
While i < str.Length
txtDrives.AppendText(str(i
i += 1
End While
Catch ex As IOException
MsgBox(ex.Message)
End Try
End Sub
ASKER
Also remember to import
imports system.io
One error i did find is that the site http://custom.programming-in.net/articles/art9-1.asp?f=GetDriveType thinks flash drives are type # 6 but all my flash drives come back as type # 2
imports system.io
One error i did find is that the site http://custom.programming-in.net/articles/art9-1.asp?f=GetDriveType thinks flash drives are type # 6 but all my flash drives come back as type # 2
https://www.experts-exchange.com/questions/21131271/Detect-removable-media.html
Dave