• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

DriveListBox Question

Hi Guys.

As you all probably know, there are 3 common types of drive shown by the DriveListBox control in VB6.

I want to set one so it only shows physical hard drives (not CD/Floppy or Network Drives).

Any Ideas?
0
NAORC
Asked:
NAORC
  • 4
1 Solution
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

Whilst populating the entries in the Combo-Box, you'll need to query the physical attributes of each drive on the system, and only add to the DriveListBox if applicable, for example:

  Dim objDrive As Object

  For Each objDrive In CreateObject("Scripting.FileSystemObject").Drives

        Select Case objDrive.DriveType
            Case 0 ' Unknown
            Case 1 ' Removable Drive
            Case 2
                  (Add objDrive.DriveLetter to your DriveListBox here)
            Case 3 ' Network Drive
            Case 4 ' CD-ROM Drive
            Case 5 ' RAM Disk Drive
            Case Else
        End Select

  Next objDrive


'

BFN,

fp.
0
 
[ fanpages ]IT Services ConsultantCommented:
Alternatively, with a known drive letter, say "A", "B", "C", "Z", etc, the following code may help...

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

Function strDriveType(ByVal strDrive As String) As String

   strDrive = Left$(Trim$(strDrive), 1) & ":\"

   Select Case (GetDriveType(strDrive))

      Case 0: strDriveType = "Unknown"
      Case 1: strDriveType = "Non-existent"
      Case 2: strDriveType = "Removable drive"
      Case 3: strDriveType = "Fixed drive"
      Case 4: strDriveType = "Network drive"
      Case 5: strDriveType = "CD-ROM drive"
      Case 6: strDriveType = "RAM disk"
      Case Else: strDriveType = "Unknown drive type"

  End Select

End Function



Usage:
MsgBox strDriveType("C")
or
MsgBox strDriveType("A")


BFN,

fp.

0
 
[ fanpages ]IT Services ConsultantCommented:
Taking this a stage further...

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

Function blnValid_Drive(ByVal strDrive As String) As Boolean

   strDrive = Left$(Trim$(strDrive), 1) & ":\"

   Select Case (GetDriveType(strDrive))

      Case (2), (3)
            blnValid_Drive = True

      Case Else
            blnValid_Drive = False

  End Select

End Function


Usage:
If blnValid_Drive("C") Then
   <Add Drive C to DriveListBox>
End If

BFN,

fp.
0
 
[ fanpages ]IT Services ConsultantCommented:
Thanks for accepting my answer.

If you needed further assistance you need not have graded as a 'B'; you could have just written another comment.

BFN,

fp.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now