How to get the PID and VID of a USB Mass Storage Device
- From: win@work <winwork@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 23 Oct 2008 09:35:01 -0700
I am trying to get the Version ID and PID of a Mass storage Device in my
application programmatically.
I am using the following code to get the VID and PID of a flash disk.But I
am getting a same value every time for all different flash disks.
Anyone knows any other way of getting VID,PID of a Flash Disk
programmatically?or is thereanything wrong in the following code?
int done = FALSE;
int drive = 0;
// for (drive = 0; drive < MAX_IDE_DRIVES; drive++)
// {
HANDLE hPhysicalDriveIOCTL = 0;
// Try to get a handle to PhysicalDrive IOCTL, report failure
// and exit if can't.
char driveName [256];
sprintf (driveName, "\\\\.\\PhysicalDrive%d", drive);
// Windows NT, Windows 2000, Windows XP - admin rights not required
hPhysicalDriveIOCTL = CreateFile (driveName, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
// if (hPhysicalDriveIOCTL == INVALID_HANDLE_VALUE)
// printf ("Unable to open physical drive %d, error code: 0x%lX\n",
// drive, GetLastError ());
if (hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE)
{
STORAGE_PROPERTY_QUERY query;
DWORD cbBytesReturned = 0;
char buffer [1000];
memset ((void *) & query, 0, sizeof (query));
query.PropertyId = StorageDeviceProperty;
query.QueryType = PropertyStandardQuery;
memset (buffer, 0, sizeof (buffer));
if ( DeviceIoControl (hPhysicalDriveIOCTL, IOCTL_STORAGE_QUERY_PROPERTY,
& query,
sizeof (query),
buffer,
sizeof (buffer),
& cbBytesReturned, NULL) )
{
STORAGE_DEVICE_DESCRIPTOR * descrip = (STORAGE_DEVICE_DESCRIPTOR *) buffer;
char serialNumber [1000];
strcpy (serialNumber,
flipAndCodeBytes ( & buffer [descrip -> SerialNumberOffset]));
if (0 == HardDriveSerialNumber [0] &&
// serial number must be alphanumeric
// (but there can be leading spaces on IBM drives)
(isalnum (serialNumber [0]) || isalnum (serialNumber [19])))
strcpy (HardDriveSerialNumber, serialNumber);
if(descrip -> VendorIdOffset)
{
strcpy(vid, &buffer [descrip -> VendorIdOffset]);
}
if(buffer [descrip -> ProductIdOffset])
{
strcpy(pid, &buffer [descrip -> ProductIdOffset]);
}
// & buffer [descrip -> ProductRevisionOffset],
//serialNumber);
}
else
{
DWORD err = GetLastError ();
char errcod[4];
sprintf(errcod,"%d",err);
char errstr[100]="DeviceIOControl IOCTL_STORAGE_QUERY_PROPERTY error code =";
strcat(errstr,errcod);
AfxMessageBox (errstr);
}
memset (buffer, 0, sizeof (buffer));
CloseHandle (hPhysicalDriveIOCTL);
}
//}
Thanks in advance!
.
- Prev by Date: get USBDSTATUS using KMDF
- Next by Date: RE: Sending ZLP with WinUSB/RAW_IO
- Previous by thread: get USBDSTATUS using KMDF
- Next by thread: Porting NDIS hook driver for Vista ( to NDIS 6.0)
- Index(es):
Relevant Pages
|