Solved

Detect USB Pen Drives

Posted on 2004-10-17
6
855 Views
Last Modified: 2008-01-09
Hi

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

Thanks
Adam
0
Comment
Question by:adam_pedley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 12335581
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12335629
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
 
LVL 18

Accepted Solution

by:
armoghan earned 500 total points
ID: 12345507
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 18

Expert Comment

by:armoghan
ID: 12345516
This is how you can get all the drives
http://www.csharphelp.com/archives2/archive363.html
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12345584
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
 
LVL 4

Author Comment

by:adam_pedley
ID: 12345599
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question