5

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?

Frank Szczerba
  • 5,000
  • 3
  • 31
  • 31
Terry
  • 581
  • 3
  • 9
  • 17

3 Answers3

6

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.

ChrisN
  • 16,635
  • 9
  • 57
  • 81
1

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

µBio
  • 10,668
  • 6
  • 38
  • 56
1

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

Apocalisp
  • 34,834
  • 8
  • 106
  • 155