'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?
Solution 1:[1]
This will give you the result on Win10
ManagementScope scope = new ManagementScope(@"\\.\root\microsoft\windows\storage");
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM MSFT_PhysicalDisk");
string type = "";
scope.Connect();
searcher.Scope = scope;
foreach (ManagementObject queryObj in searcher.Get())
{
switch (Convert.ToInt16(queryObj["MediaType"]))
{
case 1:
type = "Unspecified";
break;
case 3:
type = "HDD";
break;
case 4:
type = "SSD";
break;
case 5:
type = "SCM";
break;
default:
type = "Unspecified";
break;
}
}
searcher.Dispose();
P.s. the string type is the last drive, change to an array to get it for all drives
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Roman Podymov |
