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 hard disk information (https://www.askmehelpdesk.com/showthread.php?t=6466)

  • Dec 1, 2004, 01:39 AM
    somaraj
    How to get harddisk information
    Hi,

    I want to retrieve the hard disk information such as
    1) size
    2) Product id
    3) vendor id
    4) serial number
    5) firmware version
    6) model number

    I am able to retrieve the serial number ,firmware version and model number

    But the first 3 I am not able to retrieve . I want to know whether these information are available for a harddisk , if then how to retrive using c++

    If some one knows please help me

    Thanks in advance
    somaraj
  • Dec 6, 2004, 02:07 AM
    cremedies
    I need to know which version of Windows you are using in order to give you the location to find this information.
  • Dec 6, 2004, 03:15 AM
    somaraj
    I want my application to work on windows 2000 , given below is what I am doing .Iam not getting the vendorID .I also want whether it is slave/master.
    I don't know how to retrieve this info .




    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);
    }
    //}

  • All times are GMT -7. The time now is 02:52 AM.