Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to know if a disk is magnetic or flash

How to know if a disk is magnetic or flash

Scheduled Pinned Locked Moved C#
questioncsharpadobesysadmintutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalberts
    wrote on last edited by
    #1

    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?

    OriginalGriffO 1 Reply Last reply
    0
    • K kalberts

      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?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      K 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        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!

        K Offline
        K Offline
        kalberts
        wrote on last edited by
        #3

        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.)

        OriginalGriffO 1 Reply Last reply
        0
        • K kalberts

          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.)

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          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!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups