How to know if a disk is magnetic or flash
-
Win 10, C#: wmic calls give me the "drive type" as a small integer, a System.IO.drivetype value, running from 0 to 6. All standard disks are drive type 3, "Fixed" (or possibly type 4, "Network"). Is there any general way to distinguish between flash and magnetic "Fixed" disks? I know that I could check the manfacturer's id against a huge table identifying all the disks of all manufacturers ... There obviously is a simpler, more general way: Windows handles flash disks differently from magnetic disks. So how does Windows distinguish - and how can I do the same? Yes, I could try to do some accesses and decide based on timing. I do not consider that a clean solution. There must be a better one, but which?
-
Win 10, C#: wmic calls give me the "drive type" as a small integer, a System.IO.drivetype value, running from 0 to 6. All standard disks are drive type 3, "Fixed" (or possibly type 4, "Network"). Is there any general way to distinguish between flash and magnetic "Fixed" disks? I know that I could check the manfacturer's id against a huge table identifying all the disks of all manufacturers ... There obviously is a simpler, more general way: Windows handles flash disks differently from magnetic disks. So how does Windows distinguish - and how can I do the same? Yes, I could try to do some accesses and decide based on timing. I do not consider that a clean solution. There must be a better one, but which?
Yes, you can get it from the ManagementScope:
ManagementScope scope = new ManagementScope(@"\\\\.\\root\\microsoft\\windows\\storage"); using (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; } Console.WriteLine($"{queryObj.Path}:{type}"); } }
I didn't write that code, and it's several years old, so I no longer remember where I got it ... but it works.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
Yes, you can get it from the ManagementScope:
ManagementScope scope = new ManagementScope(@"\\\\.\\root\\microsoft\\windows\\storage"); using (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; } Console.WriteLine($"{queryObj.Path}:{type}"); } }
I didn't write that code, and it's several years old, so I no longer remember where I got it ... but it works.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
Thanks a lot. Foun other interesting filelds there as well, e.g. bus type. (What I need the info for is to give a rough estimate of the expected time to complete a set of file operations before they are actually performed. Both disk technology and bus type are essential for getting good estimates.)
-
Thanks a lot. Foun other interesting filelds there as well, e.g. bus type. (What I need the info for is to give a rough estimate of the expected time to complete a set of file operations before they are actually performed. Both disk technology and bus type are essential for getting good estimates.)
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!