Solved

search for removeable drive / USB Key

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

726 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