Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Desktops (https://www.askmehelpdesk.com/forumdisplay.php?f=427)
-   -   How to get VID and PID of a flash disk? (https://www.askmehelpdesk.com/showthread.php?t=272727)

  • Oct 23, 2008, 09:01 AM
    workv
    How to get VID and PID of a flash disk?
    Hi,
    I want to get the Product ID and Vendor ID of a USB flash disk.
    I am trying to get these information through the following code.But I am not getting it.
    Does anybody have knowledge on how to get it?
    If this method is incorrect, is there any other idea of getting the VID and PID through application for a USB flash disk?


    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!
  • Oct 23, 2008, 09:10 AM
    KISS

    This program might help you figure out what's wrong with yours. USBdView

    http://www.nirsoft.net/utils/usb_devices_view.html
  • Oct 23, 2008, 09:36 AM
    workv

    Hi,
    Thanks for suggesting me the tool.
    But I want it programmatically
    Thanks for the quick reply..

  • All times are GMT -7. The time now is 06:33 PM.