- Код: Выделить всё
Option Explicit
Const IOCTL_USB_GET_ROOT_HUB_NAME = &H220408
Const IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX = &H220448
Const IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME = &H220420
Const IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION = &H220410
Const IOCTL_USB_GET_NODE_CONNECTION_NAME = &H220414
Private Const OPEN_EXISTING = 3
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const IDENTIFY_BUFFER_SIZE = 512
Private Const OUTPUT_DATA_SIZE = IDENTIFY_BUFFER_SIZE + 16
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, lpOverlapped As Any) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Function Get_USB_Serial() As String
Dim hDrive As Long
Dim bArrOut(OUTPUT_DATA_SIZE - 1) As Byte
Dim lpcbBytesReturned As Long
Dim I As Integer
Dim TEMP As String
hDrive = CreateFile("\\?\HCD0", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, 0, 0)
DeviceIoControl hDrive, IOCTL_USB_GET_ROOT_HUB_NAME, 0, 0, bArrOut(0), OUTPUT_DATA_SIZE, lpcbBytesReturned, ByVal 0&
For I = LBound(bArrOut) To UBound(bArrOut)
If bArrOut(I) <> 0 Then
TEMP = TEMP & Chr(bArrOut(I))
End If
Next I
Get_USB_Serial = TEMP
End Function
Private Sub Command1_Click()
MsgBox Get_USB_Serial
End Sub
Всё что смог сделать. Так это вывести инфу про USB_HUB, как же продолжить и получить информацию о определённом девайсе. Знаю что нужно отсылать IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, а вот какие параметры передавать устройству в lpInBuffer незнаю. Помогите люди добрые