Hi,
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?
Thanks,
Terry
Hi,
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?
Thanks,
Terry
There's a control code you can pass to DeviceIoControl to get the physical disk geometry.
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.
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