Results 1 to 2 of 2

Thread: finding flash memory drive

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    3

    Smile finding flash memory drive

    how can I find a flash memory stick drive name using VB 6 code ? if i plug in a flash disk in different computer its drive name will change ( I:\, G:\ ...etc)

    what's the code to find it in any computer the flash memory is pluged into ?

    thanks
    Al-Mustafa

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: finding flash memory drive

    Welcome to the forums!

    See if this code helps you. It uses a drive list box, and when you change drives, it tells you the type. You could loop from C: to Z: or until you find the correct type.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const DRIVE_UNKNOWN = 0
    4. Private Const DRIVE_ABSENT = 1
    5. Private Const DRIVE_REMOVABLE = 2
    6. Private Const DRIVE_FIXED = 3
    7. Private Const DRIVE_REMOTE = 4 'Network drive
    8. Private Const DRIVE_CDROM = 5
    9. Private Const DRIVE_RAMDISK = 6
    10.  
    11. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
    12. (ByVal nDrive As String) As Long
    13.  
    14. Dim DriveLetter As String
    15.  
    16. Private Function TestDrive(ByVal strDrive As String) As Boolean
    17.     If GetDriveType(strDrive) = 4 Then
    18.         TestDrive = True
    19.     Else
    20.         TestDrive = False
    21.     End If
    22. End Function
    23.  
    24. Private Sub Command1_Click()
    25.   Dim drivetype As Integer
    26.   Dim typemsg As String
    27.   drivetype = (GetDriveType(DriveLetter))
    28.   Select Case drivetype
    29.   Case 0
    30.     typemsg = "DRIVE_UNKNOWN"
    31.   Case 1
    32.     typemsg = "DRIVE_ABSENT"
    33.   Case 2
    34.     typemsg = "DRIVE_REMOVABLE"
    35.   Case 3
    36.     typemsg = "DRIVE_FIXED"
    37.   Case 4
    38.     typemsg = "DRIVE_REMOTE / Network Drive"
    39.   Case 5
    40.    typemsg = "DRIVE_CDROM"
    41.   Case 6
    42.    typemsg = "DRIVE_RAMDISK?"
    43.   End Select
    44.  
    45.   MsgBox "Drive " & UCase(DriveLetter) & "\ = " & typemsg
    46. End Sub
    47.  
    48. Private Sub Drive1_Change()
    49.   DriveLetter = Drive1.Drive
    50. End Sub
    51.  
    52. Private Sub Form_Load()
    53.   DriveLetter = Drive1.Drive
    54. End Sub

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