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 / C++ / MFC
  4. Getting LogicalDriveInformation of different hard disks.....

Getting LogicalDriveInformation of different hard disks.....

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 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.
  • L Offline
    L Offline
    learningvisualc
    wrote on last edited by
    #1

    Hi all, If i have more then one hard disk in my system then how can i get its logical drive information in a format like Hard disk first then C:/,D:/...Then Hard disk2 E:/,F:/... GetLogicalDrive() function retrieves all the Logical drives. How can i do this??? Thanks in advance...

    L L D 3 Replies Last reply
    0
    • L learningvisualc

      Hi all, If i have more then one hard disk in my system then how can i get its logical drive information in a format like Hard disk first then C:/,D:/...Then Hard disk2 E:/,F:/... GetLogicalDrive() function retrieves all the Logical drives. How can i do this??? Thanks in advance...

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      GetLogicalDrives returns an integer where each bit represents a drive letter which is either present (1) or not (0). The least significant bit means A: and then each next bit is one letter up. So in order to check for the presence of drive C:, you'd test the 3rd bit:

      if(GetLogicalDrives() & 4)
      	printf("Drive C: is present.");
      

      The number 4 to AND with is represented as 00000000000000000000000000000100 in binary, so in effect you check if the 3rd bit is set. You can use GetDriveType[^] to determine if a drive is a hard disk or something else, like a CD-ROM or network drive.

      1 Reply Last reply
      0
      • L learningvisualc

        Hi all, If i have more then one hard disk in my system then how can i get its logical drive information in a format like Hard disk first then C:/,D:/...Then Hard disk2 E:/,F:/... GetLogicalDrive() function retrieves all the Logical drives. How can i do this??? Thanks in advance...

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        I know of three ways: 1. There are a number of Win32 functions for this in kernel32.dll; they include GetDriveType, GetVolumeInformation, GetDiskFreeSpaceEx, and maybe more. 2. reading some keys in the registry. This is not recommended, and may trigger a UAC dialog, or fail, for non-admin accounts under Vista/Win7. 3. the WMI classes provide a lot of information (e.g. Win32_DiskDrive, Win32_LogicalDiskToPartition, Win32_PhysicalMedia, Win32_CDROMDrive). WMI works like a database, and it allows to query for other systems on the network. :)

        Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum

        Season's Greetings to all CPians.

        1 Reply Last reply
        0
        • L learningvisualc

          Hi all, If i have more then one hard disk in my system then how can i get its logical drive information in a format like Hard disk first then C:/,D:/...Then Hard disk2 E:/,F:/... GetLogicalDrive() function retrieves all the Logical drives. How can i do this??? Thanks in advance...

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          learningvisualc wrote:

          How can i do this???

          Are you wanting to know what logical drives belong to each physical drive? If so, see here. It's VB, but can easily be converted.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          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