Results 1 to 5 of 5

Thread: Valid Drives

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Ocotlan, Jalisco, Mexico
    Posts
    18

    Question

    Is there a way to find out how many drives a PC has?
    ie:
    a:,b:,c:,d:,e:

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Use the DriveListBox control.


  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Ocotlan, Jalisco, Mexico
    Posts
    18
    is there a way to do it with an API?

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Code:
    Declare Function GetLogicalDrives Lib "kernel32.dll" () As Long
    
    Dim driveflags As Long  ' receives the flags identifying valid drives
    
    ' Tell the user which drives exist on the computer.  Note how this example
    ' only checks up to drive D:, but it does establish the necessary pattern to use in general.
    Dim driveflags As Long  ' receives the flags identifying valid drives
    
    driveflags = GetLogicalDrives()
    ' Test the returned value to see if drives A: through D: exist.
    If (driveflags And 1) = 1 Then Debug.Print "Drive A: exists."
    If (driveflags And 2) = 2 Then Debug.Print "Drive B: exists."
    If (driveflags And 4) = 4 Then Debug.Print "Drive C: exists."
    If (driveflags And 8) = 8 Then Debug.Print "Drive D: exists."

  5. #5
    Lively Member
    Join Date
    Nov 2000
    Posts
    82
    You can use the following API and routine to check for the existence and type of each drive:

    API:
    Code:
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

    Calling Code:
    Code:
    For i = 65 to 90
       x$=GetDrive(Chr(i))
       Debug.Print x$
    Next i

    Routine:
    Code:
    Public Function GetDrive(sDrive As String) As String
    
        On Error GoTo Error_Handler:
    
    ' This routine calls the API GetDriveType. That routine will return
    ' a long value that equates to a description as shown.
    ' Sample Call: GetDrive "C"
        
        Select Case GetDriveType(sDrive & ":\")
            Case 2
                GetDrive = "Removable"
            Case 3
                GetDrive = "Drive Fixed"
            Case 4
                GetDrive = "Remote"
            Case 5
                GetDrive = "Cd-Rom"
            Case 6
                GetDrive = "Ram disk"
            Case Else
                GetDrive = "Unrecognized"
        End Select
    End Function


    [Edited by Jeff Carlin on 11-18-2000 at 11:43 AM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width