Solved

search for removeable drive / USB Key

Posted on 2006-06-22
3
163 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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