Start New Discussion within our Software Development Community

Is there a way to get the hard drive letter with VB 4.0?
I have an older program written in this language that I am attempting to modify
and need to get the hard drive letter to update it.

Thanks for your help.


Not sure in vb4. In vb6 you will be using something similar to -

Public Const Drive_Unknown = 0
Public Const Drive_NoRootDir = 1
Public Const Drive_Removable = 2
Public Const Drive_Fixed = 3
Public Const Drive_Remote = 4
Public Const Drive_CDRom = 5
Public Const Drive_RamDisk = 6

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

Dim A As Long
Dim ABC As String
Dim Temp As Long
Dim Desc As String


For A = 1 To Len(ABC)
    Temp = GetDriveType(Mid(ABC, A, 1) & ":\")

    Desc = ""
    Select Case Temp
    Case Drive_Unknown
        Desc = "Unknown"
    Case Drive_NoRootDir
        'Desc = "No root directory"
    Case Drive_CDRom
        Desc = "CDRom"
    Case Drive_Fixed
        Desc = "HD"
    Case Drive_RamDisk
        Desc = "Ram drive"
    Case Drive_Remote
        Desc = "Remote"
    Case Drive_Removable
        Desc = "Removable disc"
    End Select

    If Not Desc Like "" Then: Combo1.AddItem Mid(ABC, A, 1) & " - " & Desc

Thank you Andre. The code worked GREAT without any changes. Before I close this thread, can you tell me why it only returns the hard drive versus all of the drive letters? I noticed that 'ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and that the counter cycles through all of the drive letters. I get: "C - Unknown" when I run the code.

Thanks again!!!!!!!!!

Only a pleasure. I've tested the code on my side and it returned all the correct descriptions...

even my removable disk - I- Removable disc

I tested on Windows 7 and Vista. Not sure if XP will return the correct values.

Here is another option using the FileSystemObject

Sub ListDrives()
    Dim fso As Scripting.FileSystemObject 'needs refernce to: Microsoft Scripting Runtime
    Dim fsoDrives As Scripting.drives

    Set fso = New FileSystemObject
    Set fsoDrives = fso.drives
    Dim i As Integer
    Dim letter As String
    Dim driveType As String
    For i = Asc("A") To Asc("Z")
        letter = Chr$(i)
        If fso.DriveExists(letter) Then
            Select Case fso.drives(letter).driveType 'returns DriveTypeConst
                Case Scripting.UnknownType
                    driveType = "Unknown"
                Case Scripting.Removable
                    driveType = "Removable"
                Case Scripting.Fixed
                    driveType = "Fixed"
                Case Scripting.Remote
                    driveType = "Remote"
                Case Scripting.CDRom
                    driveType = "CDRom"
                Case Scripting.RamDisk
                    driveType = "RamDisk"
            End Select
            MsgBox "Drive " & letter & " - " & driveType
        End If
    Next i

    Set fsoDrives = Nothing
    Set fso = Nothing

End Sub
This question has already been answered. Start a new discussion instead.