Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

search for removeable drive / USB Key

Posted on 2006-06-22
3
Medium Priority
?
168 Views
Last Modified: 2010-04-30
I am looking for a way to programatically determine the drive letters of removeable drives in Windows (specifically USB keys) so that I may find a particular executable and run it.
0
Comment
Question by:bc4942
[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
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 16960861
You can list the drive types for each letter.

I have this on a form.

Option Explicit

Private Sub Command1_Click()
Dim i As Integer
For i = 65 To 90
Debug.Print Chr$(i), DriveType(Chr$(i))
Next i
End Sub

In a module

Option Explicit

Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Public Function DriveType(sDrive As String) As String
    Dim sDriveName As String
    Const DRIVE_TYPE_UNDTERMINED = 0
    Const DRIVE_ROOT_NOT_EXIST = 1
    Const DRIVE_REMOVABLE = 2
    Const DRIVE_FIXED = 3
    Const DRIVE_REMOTE = 4
    Const DRIVE_CDROM = 5
    Const DRIVE_RAMDISK = 6
   
    sDriveName = GetDriveType(sDrive & ":\")
    Select Case sDriveName
        Case DRIVE_TYPE_UNDTERMINED
            DriveType = "unknown"
        Case DRIVE_ROOT_NOT_EXIST
            DriveType = "non-existent"
        Case DRIVE_CDROM
            DriveType = "CD-ROM"
        Case DRIVE_FIXED
            DriveType = "local"
        Case DRIVE_RAMDISK
            DriveType = "RAM"
        Case DRIVE_REMOTE
            DriveType = "remote"
        Case DRIVE_REMOVABLE
            DriveType = "removeable"
    End Select
  End Function

0
 

Author Comment

by:bc4942
ID: 16961011
Excellent!  Exactly what I was looking for!!
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 16961698
That's good news. Thanks. Good luck.
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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 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