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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Retrieve the Name of a Disk Drive

Retrieve the Name of a Disk Drive

Scheduled Pinned Locked Moved C#
csharpcomhardwarejsonhelp
6 Posts 3 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.
  • M Offline
    M Offline
    Mark Sanders
    wrote on last edited by
    #1

    Here is the situation: I am writing an application that needs to detect a specific USB MMC card reader connected to the computer. I need to do this so that I can make the default save path for my application automatically be the card reader. Possible Solution to Try: An idea that I have is to check each drive on the computer and when the name of the drive matches the name of the reader I will know I have the right drive. I don't know how to get the name of the drive programatically but on my Windows XP Pro Machine I... 1. Open Windows Explorer. 2. Right click on the reader (labeled "Removable Disk (F)") 3. Select Properties. 4. Select the Hardware tab from the Removable Disk Properties. 5. Under the hardware tab there will be a list of "All disk drives:". In this list the specific name of the reader is listed as "eUSB Secure Digital USB Device." "eUSB Secure Digital USB Device" is the name that I need. This name is also displayed under "Disk Drives" in the "Device Manager". Suggestions: 1. Do you think this is a good idea to try? 2. Do you know how to do an part of the above proposal programatically? I would like to stay in C# as much as possible but I have a feeling this is only going to be able to be done using the Windows API or some other non-.NET way. Thank you for your help. :) Mark Sanders sanderssolutions.com

    T 1 Reply Last reply
    0
    • M Mark Sanders

      Here is the situation: I am writing an application that needs to detect a specific USB MMC card reader connected to the computer. I need to do this so that I can make the default save path for my application automatically be the card reader. Possible Solution to Try: An idea that I have is to check each drive on the computer and when the name of the drive matches the name of the reader I will know I have the right drive. I don't know how to get the name of the drive programatically but on my Windows XP Pro Machine I... 1. Open Windows Explorer. 2. Right click on the reader (labeled "Removable Disk (F)") 3. Select Properties. 4. Select the Hardware tab from the Removable Disk Properties. 5. Under the hardware tab there will be a list of "All disk drives:". In this list the specific name of the reader is listed as "eUSB Secure Digital USB Device." "eUSB Secure Digital USB Device" is the name that I need. This name is also displayed under "Disk Drives" in the "Device Manager". Suggestions: 1. Do you think this is a good idea to try? 2. Do you know how to do an part of the above proposal programatically? I would like to stay in C# as much as possible but I have a feeling this is only going to be able to be done using the Windows API or some other non-.NET way. Thank you for your help. :) Mark Sanders sanderssolutions.com

      T Offline
      T Offline
      thematt
      wrote on last edited by
      #2

      Mark Sanders wrote: 1. Open Windows Explorer. 2. Right click on the reader (labeled "Removable Disk (F)") 3. Select Properties. 4. Select the Hardware tab from the Removable Disk Properties. 5. Under the hardware tab there will be a list of "All disk drives:". In this list the specific name of the reader is listed as "eUSB Secure Digital USB Device." I can get the same type of information using WMI about my IDE drives. I hope it works for the USB device: private void button1_Click_1(object sender, System.EventArgs e) { String scope = "\\root\\cimv2"; ManagementScope ms = new ManagementScope(scope); ObjectQuery oq = new ObjectQuery("Select * from win32_diskdrive"); ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq); ManagementObjectCollection moc = mos.Get(); foreach(ManagementObject mo in moc) { txtOutput.AppendText(mo["caption"].ToString() + "\r\n"); } } Of course you must have WMI on the system. Matt is a network administrator for an insurance company in the midwest. He is shamelessly looking for Windows programming side work.

      M 1 Reply Last reply
      0
      • T thematt

        Mark Sanders wrote: 1. Open Windows Explorer. 2. Right click on the reader (labeled "Removable Disk (F)") 3. Select Properties. 4. Select the Hardware tab from the Removable Disk Properties. 5. Under the hardware tab there will be a list of "All disk drives:". In this list the specific name of the reader is listed as "eUSB Secure Digital USB Device." I can get the same type of information using WMI about my IDE drives. I hope it works for the USB device: private void button1_Click_1(object sender, System.EventArgs e) { String scope = "\\root\\cimv2"; ManagementScope ms = new ManagementScope(scope); ObjectQuery oq = new ObjectQuery("Select * from win32_diskdrive"); ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq); ManagementObjectCollection moc = mos.Get(); foreach(ManagementObject mo in moc) { txtOutput.AppendText(mo["caption"].ToString() + "\r\n"); } } Of course you must have WMI on the system. Matt is a network administrator for an insurance company in the midwest. He is shamelessly looking for Windows programming side work.

        M Offline
        M Offline
        Mark Sanders
        wrote on last edited by
        #3

        Thank you for your reply. I will mess around with your example to see if it gives me any other leads but I don't think I will be able to use it for my application. The application I am writing needs to be able to run on any client computer running Win98, Me, 2000, or XP. I don't think I will be able to guarantee WMI on the computer in which the app is installed. I don't know much about WMI, so if my statements above are not true let me know. Mark Sanders sanderssolutions.com

        T 1 Reply Last reply
        0
        • M Mark Sanders

          Thank you for your reply. I will mess around with your example to see if it gives me any other leads but I don't think I will be able to use it for my application. The application I am writing needs to be able to run on any client computer running Win98, Me, 2000, or XP. I don't think I will be able to guarantee WMI on the computer in which the app is installed. I don't know much about WMI, so if my statements above are not true let me know. Mark Sanders sanderssolutions.com

          T Offline
          T Offline
          thematt
          wrote on last edited by
          #4

          WMI is available only as an add on to Win98 so this is not a good solution for you. I figured the platform would be a problem with this answer but thought I would post anyway. Matt is a network administrator for an insurance company in the midwest. He is shamelessly looking for Windows programming side work.

          M 1 Reply Last reply
          0
          • T thematt

            WMI is available only as an add on to Win98 so this is not a good solution for you. I figured the platform would be a problem with this answer but thought I would post anyway. Matt is a network administrator for an insurance company in the midwest. He is shamelessly looking for Windows programming side work.

            M Offline
            M Offline
            Mark Sanders
            wrote on last edited by
            #5

            Thanks for tryin'. Mark Sanders sanderssolutions.com

            F 1 Reply Last reply
            0
            • M Mark Sanders

              Thanks for tryin'. Mark Sanders sanderssolutions.com

              F Offline
              F Offline
              fhsBlue
              wrote on last edited by
              #6

              > Hey! i just checked out ur email so I am answering. The other way: > //Get Drive list...getDrives() implementaion last lines... ManagementObjectCollection queryCollection = getDrives(); //Loop Here...Iterate through each Node.... foreach ( ManagementObject mo in queryCollection) { switch (int.Parse( mo["DriveType"].ToString())) { case 2: //removable drives = 2 (A:\)etc... numberofRemovable++; break; case 3: //Local drives (C:\;D:\;E:\) numberofLocalDisk++; break; case 5: //CD rom drives(F:\;G:\) numberofCD++; break; case 4: //Network drives numberofNetworkdrv++; break; default: //default to folder break; } //objects = ArrayList Object here.. objects.Add(mo["Name"].ToString); }//loop end ///////////////////////////////////////////////////////// /// /// Gets the lists of the logical disks and their infos.. ///////////////////////////////////////////////////////// protected ManagementObjectCollection getDrives() { //get drive collection ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk "); ManagementObjectCollection queryCollection = query.Get(); return queryCollection; } /////////////////////////////////////////////////////////// I hope this will work for ur application too... regards, fahad... I wish not to seem but to be the Best.... F a h a d H. Siddiqui

              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