Solved

search for removeable drive / USB Key

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Write data from SQL to CSV file - position 1 52
VBA/SQL - Connect to SQL server and pull data 4 88
Using "ScreenUpdating" 6 55
Access 2013 combo box not working 3 38
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

911 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

18 Experts available now in Live!

Get 1:1 Help Now