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
Printable View
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
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:
Option Explicit Private Const DRIVE_UNKNOWN = 0 Private Const DRIVE_ABSENT = 1 Private Const DRIVE_REMOVABLE = 2 Private Const DRIVE_FIXED = 3 Private Const DRIVE_REMOTE = 4 'Network drive Private Const DRIVE_CDROM = 5 Private Const DRIVE_RAMDISK = 6 Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _ (ByVal nDrive As String) As Long Dim DriveLetter As String Private Function TestDrive(ByVal strDrive As String) As Boolean If GetDriveType(strDrive) = 4 Then TestDrive = True Else TestDrive = False End If End Function Private Sub Command1_Click() Dim drivetype As Integer Dim typemsg As String drivetype = (GetDriveType(DriveLetter)) Select Case drivetype Case 0 typemsg = "DRIVE_UNKNOWN" Case 1 typemsg = "DRIVE_ABSENT" Case 2 typemsg = "DRIVE_REMOVABLE" Case 3 typemsg = "DRIVE_FIXED" Case 4 typemsg = "DRIVE_REMOTE / Network Drive" Case 5 typemsg = "DRIVE_CDROM" Case 6 typemsg = "DRIVE_RAMDISK?" End Select MsgBox "Drive " & UCase(DriveLetter) & "\ = " & typemsg End Sub Private Sub Drive1_Change() DriveLetter = Drive1.Drive End Sub Private Sub Form_Load() DriveLetter = Drive1.Drive End Sub