Determining disk geometry in Windows

I need to programmatically determine how many sectors, heads and cylinders are on a physical disk with Windows XP. Does anyone know an API to define this? Where can Windows provide this information?

+5
source share
3 answers

Use DeviceIoControl with the control code IOCTL_DISK_GET_DRIVE_GEOMETRY or IOCTL_DISK_GET_DRIVE_GEOMETRY_EX .

Here's a sample code on MSDN for here .

+5
source
+1

WMI is good at this too, I have 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 disk properties, you can use this page.

+1
source

All Articles