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 / C++ / MFC
  4. How to get the PhysicalDrive number which the logical drive located?

How to get the PhysicalDrive number which the logical drive located?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 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.
  • E Offline
    E Offline
    EastDragon
    wrote on last edited by
    #1

    How to get the PhysicalDrive number which the logical drive located? Like how to get the PhysicalDrive number of "C:" logical drive ? Thanks a lot!


    Let's roll!

    T T J 3 Replies Last reply
    0
    • E EastDragon

      How to get the PhysicalDrive number which the logical drive located? Like how to get the PhysicalDrive number of "C:" logical drive ? Thanks a lot!


      Let's roll!

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

      HI Dragon, have a look at Win32_DiskDrive WMI Class!

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta

      1 Reply Last reply
      0
      • E EastDragon

        How to get the PhysicalDrive number which the logical drive located? Like how to get the PhysicalDrive number of "C:" logical drive ? Thanks a lot!


        Let's roll!

        T Offline
        T Offline
        Tuscon
        wrote on last edited by
        #3

        LPTSTR lpVolumeNameBuffer[100]; LPDWORD lpVolumeSerialNumber; LPDWORD lpMaximumComponentLength; LPDWORD lpFileSystemFlags; LPTSTR lpFileSystemNameBuffer[100]; GetVolumeInformation("C:\\",lpVolumeNameBuffer,100,&lpVolumeSerialNumber, lpMaximumComponentLength,lpFileSystemFlags,lpFileSystemNameBuffer,100 ); use the above function it returns the Volume Serial Number of the physical C drive . Cheers :)

        J 1 Reply Last reply
        0
        • T Tuscon

          LPTSTR lpVolumeNameBuffer[100]; LPDWORD lpVolumeSerialNumber; LPDWORD lpMaximumComponentLength; LPDWORD lpFileSystemFlags; LPTSTR lpFileSystemNameBuffer[100]; GetVolumeInformation("C:\\",lpVolumeNameBuffer,100,&lpVolumeSerialNumber, lpMaximumComponentLength,lpFileSystemFlags,lpFileSystemNameBuffer,100 ); use the above function it returns the Volume Serial Number of the physical C drive . Cheers :)

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #4

          Hmmm.  How about: TCHAR caVolumeNameBuffer[ 100 ]; DWORD dwVolumeSerialNumber = 0; DWORD dwMaximumComponentLength = 0; DWORD dwFileSystemFlags = 0; TCHAR caFileSystemNameBuffer[ 100 ]; GetVolumeInformation( _T( "C:\\" ), caVolumeNameBuffer, 100, &dwVolumeSerialNumber, &dwMaximumComponentLength, &dwFileSystemFlags, caFileSystemNameBuffer, 100 );    Your example was not passing in valid pointers, only uninitialized ones.  Might want to ensure proper termination of the TCHAR buffers as well.    However, I think the OP was asking about the physical device name for the drive, not its serial number; I think they were looking for information such as if a drive is \\.\PhysicalDrive0 or \\.\PhysicalDrive1, etc.  You need that information to open the device itself (the hard drive itself) to do things like send IOCTLs.  I do not think that the function you specified will return that information.    Peace! -=- James


          If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          DeleteFXPFiles & CheckFavorites (Please rate this post!)

          1 Reply Last reply
          0
          • E EastDragon

            How to get the PhysicalDrive number which the logical drive located? Like how to get the PhysicalDrive number of "C:" logical drive ? Thanks a lot!


            Let's roll!

            J Offline
            J Offline
            James R Twine
            wrote on last edited by
            #5

            If you need that to do something like send IOCTLs (DeviceIoControl), you can also open the device by using the following syntax:      \\.\C:    - Open physical device for drive "C"      \\.\D:    - Open physical device for drive "D"      \\.\A:    - Open physical device for drive "A"    I do not know all of the cases where that format and the \\.\PhysicalDrive_**x**_ format are interchangable, but I know you can use it when getting a HANDLE to use with DeviceIoControl.    Also, not that you are likely to hit it, but there is a bug in older versions of the Win32_DiskDrive WMI class that limits the number of drives returned.  The above method should also work on Windows NT 4.0 versions prior to SP4, but the WMI method will not.    Peace! -=- James


            If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            DeleteFXPFiles & CheckFavorites (Please rate this post!)

            E 1 Reply Last reply
            0
            • J James R Twine

              If you need that to do something like send IOCTLs (DeviceIoControl), you can also open the device by using the following syntax:      \\.\C:    - Open physical device for drive "C"      \\.\D:    - Open physical device for drive "D"      \\.\A:    - Open physical device for drive "A"    I do not know all of the cases where that format and the \\.\PhysicalDrive_**x**_ format are interchangable, but I know you can use it when getting a HANDLE to use with DeviceIoControl.    Also, not that you are likely to hit it, but there is a bug in older versions of the Win32_DiskDrive WMI class that limits the number of drives returned.  The above method should also work on Windows NT 4.0 versions prior to SP4, but the WMI method will not.    Peace! -=- James


              If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
              Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
              DeleteFXPFiles & CheckFavorites (Please rate this post!)

              E Offline
              E Offline
              EastDragon
              wrote on last edited by
              #6

              Thanks a lot! I just need to use \\.\PhysicalDrivex to open the disk contains the appointed logical volumn. I've lookup in MSDN and found the method. Use DeviceIoControl and send IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS. But MSDN says it can only use in win2000 and later version.


              Let's roll!

              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