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

Thread: Identification of USB flash disk in VB6

  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
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    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!

  7. #7
    Join Date
    Feb 2008
    Posts
    7

    Re: Identification of USB flash disk in VB6

    But this only tells that drive "H:\" is removable or not. It I already know... How can I get VID and PID for this drive?

  8. #8
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: Identification of USB flash disk in VB6

    Either way, you are going to have to read the registry as I have already stated. I also gave you the key. You will have to loop through all connected drives and get there model. Then you can easily match that up with the values stored in the following key.

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

  9. #9
    Join Date
    Feb 2008
    Posts
    7

    Re: Identification of USB flash disk in VB6

    I am sorry but I still don't understand you...

    When I look in registry I found realy many informations about every USB disk. But how I can decide which registry record matches my disk connected as drive "H:\" ??? What compare with what?
    All I know about my disk is path "H:\" and I want to get it's VID and PID to say "YES! It's my disk!". How can I do it?

    By the other way I want to get VID and PID of USB disk represented by drive letter... I know drive letter and I want to get VID and PID.

    Does exist any easy API call to solve this thing?

  10. #10
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: Identification of USB flash disk in VB6

    Quote Originally Posted by nebozez
    Does exist any easy API call to solve this thing?
    No. And that is why we aren't giving one to you. If one did, we would have already provided it.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)