-
February 18th, 2008, 09:09 AM
#1
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.
-
February 18th, 2008, 10:58 AM
#2
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.
-
February 19th, 2008, 01:21 AM
#3
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?
-
February 19th, 2008, 02:04 AM
#4
Re: Identification of USB flash disk in VB6
How does the disk know? It doesn't have that info.
-
February 19th, 2008, 02:36 AM
#5
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)
-
February 19th, 2008, 02:40 AM
#6
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
-
February 19th, 2008, 03:29 AM
#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?
-
February 19th, 2008, 08:42 AM
#8
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.
-
February 19th, 2008, 09:14 AM
#9
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?
-
February 19th, 2008, 09:21 AM
#10
Re: Identification of USB flash disk in VB6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|