Question

I need to programmatically determine out how many sectors, heads, and cylinders are on a physical disk from Windows XP. Does anyone know the API for determining this? Where might Windows expose this information?

Was it helpful?

Solution

Use DeviceIoControl with control code IOCTL_DISK_GET_DRIVE_GEOMETRY or IOCTL_DISK_GET_DRIVE_GEOMETRY_EX.

There's sample code in MSDN to do this here.

OTHER TIPS

There's a control code you can pass to DeviceIoControl to get the physical disk geometry.

WMI is good at this too, I've used it with great success.

using( ManagementClass driveClass = new ManagementClass( "Win32_DiskDrive" ) )
{
    using( ManagementObjectCollection physicalDrives = driveClass.GetInstances( ) )
    {
        foreach( ManagementObject drive in physicalDrives )
        {
            string cylinders = ( string )drive["TotalCylinders"];
            // ... etc ...
            drive.Dispose( );
        }
    }
}

For a list of additional drive properties you can use, check out this page

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top