Ask Experts Questions for FREE Help !
Ask
    workv's Avatar
    workv Posts: 2, Reputation: 1
    New Member
     
    #1

    Oct 23, 2008, 09:01 AM
    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!
    KISS's Avatar
    KISS Posts: 12,510, Reputation: 839
    Uber Member
     
    #2

    Oct 23, 2008, 09:10 AM

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

    http://www.nirsoft.net/utils/usb_devices_view.html
    workv's Avatar
    workv Posts: 2, Reputation: 1
    New Member
     
    #3

    Oct 23, 2008, 09:36 AM

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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Portable hard disk disk not opening [ 7 Answers ]

I inserted my portable hard disk in the usb drive and before opening scanned it for viruses.after about half the scan the scanning got stuck at one point.at that instant all programs became non responsive. I then removed my portable disk immediately.then all programs became responsive. But when I...

Help! Need help making movies with flash macromedia flash pro 8 [ 23 Answers ]

Help! I need to animate this movie sort of like a cartoon for example if I wanted a stick man ( example) and I want it to throw a stick then run. This is very hard because I make the man and I have to modify and modify every slide s the man can like move his hand. There must be an easier way. Need...

LG Flash disk [ 1 Answers ]

I am using an LG Flash disk and it is write protected. It does not have the write protect switch. How can I undo this problem since saving & retrieving documents in the LG flash disk is not possible. Kindly assist.

Flash Action Script-Programming in Flash cs3 professional [ 1 Answers ]

Hi Does anybody know 1. method to creating a folder using Flash action script ? 2.Any good sites to learn Flash action script ? 3.Code to make a button in flash to browse for a image file and then to display its path? Thanks in Advance.. :)


View more questions Search