Solved

Detect USB Pen Drives

Posted on 2004-10-17
6
868 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

719 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