What is the easiest way in C# to check if hard disk is SSD without writing any file on hard disk?

蹲街弑〆低调 提交于 2019-11-29 12:20:55

问题


I need to check in C# if a hard disk is SSD (Solid-state drive), no seek penalty? I used:

    ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");
    ManagementObjectCollection drives = driveClass.GetInstances(); 

But its only gives Strings that contain SSD in the properties, I can't depend on that?

I Need a direct way to check that?


回答1:


WMI will not be able to determine this easily. There is a solution here that's based on the same algorithm Windows 7 uses to determine if a disk is SSD (more on the algorithm here: Windows 7 Enhancements for Solid-State Drives, page 8 and also here: Windows 7 Disk Defragmenter User Interface Overview): Tell whether SSD or not in C#

A quote from the MSDN blog:

Disk Defragmenter looks at the result of directly querying the device through the ATA IDENTIFY DEVICE command. Defragmenter issues IOCTL_ATA_PASS_THROUGH request and checks IDENTIFY_DEVICE_DATA structure. If the NomimalMediaRotationRate is set to 1, this disk is considered a SSD. The latest SSDs will respond to the command by setting word 217 (which is used for reporting the nominal media rotation rate to 1). The word 217 was introduced in 2007 in the ATA8-ACS specification.



来源:https://stackoverflow.com/questions/13726522/what-is-the-easiest-way-in-c-sharp-to-check-if-hard-disk-is-ssd-without-writing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!