Solved

search for removeable drive / USB Key

Posted on 2006-06-22
3
161 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
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now