CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    7

    Exclamation Identification of USB flash disk in VB6

    Hi all!

    I need help in VB6 under Win XP. I need to read VID and PID of my USB flash disk in VB6. I googled many examples but nothing works

    My disk is connected for example as drive "I:\" and by some utilities I found that it has both VID and PID. How to read this information in VB6?

    I need something easy like:

    Code:
    dim VID
    dim PID 
    
    sub GetVIDandPID(Path as string) 
       ...??? something to get VID and PID ???...  
    end sub 
    
    sub main()
       GetVIDandPID "I:\" 
       msgbox VID & " " & PID 
    end sub
    I will be very happy if anybody knows some method which WORKS!

    Thanks a lot.
    Last edited by PeejAvery; February 18th, 2008 at 10:50 AM. Reason: Added code tags.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Identification of USB flash disk in VB6

    Well, it is stored in the registry. All you need to do is parse the string out of the key.

    HKEY_CURRENT_CONFIG\System\CurrentControlSet\Enum\USBSTOR
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Feb 2008
    Posts
    7

    Re: Identification of USB flash disk in VB6

    But I need to detect if disc specified by VID and PID is connected now or not... I dont want to read info from registry but from the disk.

    Any idea?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Identification of USB flash disk in VB6

    How does the disk know? It doesn't have that info.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Feb 2008
    Posts
    7

    Re: Identification of USB flash disk in VB6

    But if VID and PID are both hardware dependent and unique so it must be stored "on disk". Is not it? So for example how can I read VID and PID from disk "H:\"? (I know that it is USB disk)

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Identification of USB flash disk in VB6

    Why not just read from the registry? You can use this API:

    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
    But it is just REMOVEABLE
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured