Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 423
Khaleel Hmoz Avatar asked Dec 05 '12 15:12

Khaleel Hmoz


People also ask

What is the fastest way to learn C?

Get started with C. Official C documentation - Might be hard to follow and understand for beginners. Visit official C Programming documentation. Write a lot of C programming code - The only way you can learn programming is by writing a lot of code.

Is C easy for beginners?

C language is simple and easy to learn. C is a machine independent language, which means a C program written one machine can run on another machine without requiring a code change. C is a compiler based language and it supports only useful features which makes the compilation of C file fast.

Which C language is easy?

C++ C++, an extension of C—which we said was an easy language to learn—is a general-purpose programming language.

Can I learn C in a week?

That is simply not possible. You could learn HTML, CSS or any other simple language in a week but C is an OOP language meaning it has tons of concepts to learn which for a beginner takes a lot of time to understand no matter how intelligent you are. C for an average person is about 6–8 months of learning.


1 Answers

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.

like image 116
Simon Mourier Avatar answered Oct 17 '22 18:10

Simon Mourier