Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 904
  • Last Modified:

Detect USB Pen Drives

Hi

Is it possible in vb to detect any USB Pen drives attached to the computer?

Thanks
Adam
0
adam_pedley
Asked:
adam_pedley
  • 3
  • 2
1 Solution
 
adam_pedleyAuthor Commented:
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
0
 
armoghanCommented:
Get all drives and iterate through all the derive types and see there type

see the following links for device type
http://www.codeproject.com/csharp/bienzsysinfo.asp
http://custom.programming-in.net/articles/art9-1.asp?f=GetDriveType
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
armoghanCommented:
This is how you can get all the drives
http://www.csharphelp.com/archives2/archive363.html
0
 
adam_pedleyAuthor Commented:
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
0
 
adam_pedleyAuthor Commented:
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

0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now