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. how to identify the drive type?

how to identify the drive type?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasecomhelptutorial
9 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.
  • V Offline
    V Offline
    VCProgrammer
    wrote on last edited by
    #1

    hi all, i am getting all drives list connected in my system. as list of logical drive and physical drive. for logical drives i m using GetLogicalDrives() and for physical drives using com with this query "Win32_DiskDrive". but how can i indetify which drive is external drive in out of all drive for both logical and physical. please help me for this. thank in advance.

    L 1 Reply Last reply
    0
    • V VCProgrammer

      hi all, i am getting all drives list connected in my system. as list of logical drive and physical drive. for logical drives i m using GetLogicalDrives() and for physical drives using com with this query "Win32_DiskDrive". but how can i indetify which drive is external drive in out of all drive for both logical and physical. please help me for this. thank in advance.

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

      You could always check the documentation[^].

      One of these days I'm going to think of a really clever signature.

      V 1 Reply Last reply
      0
      • L Lost User

        You could always check the documentation[^].

        One of these days I'm going to think of a really clever signature.

        V Offline
        V Offline
        VCProgrammer
        wrote on last edited by
        #3

        this is working only for physical disk drive i have done this with MediaType parameter with "External hard disk media" value. now what can i use for logical drives.

        L 1 Reply Last reply
        0
        • V VCProgrammer

          this is working only for physical disk drive i have done this with MediaType parameter with "External hard disk media" value. now what can i use for logical drives.

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

          Since a physical drive can contain many logical drives it probably does not make sense for logical. You probably need to find the logical drive's parent device and check that.

          One of these days I'm going to think of a really clever signature.

          V 1 Reply Last reply
          0
          • L Lost User

            Since a physical drive can contain many logical drives it probably does not make sense for logical. You probably need to find the logical drive's parent device and check that.

            One of these days I'm going to think of a really clever signature.

            V Offline
            V Offline
            VCProgrammer
            wrote on last edited by
            #5

            ok so how can i get its parent disk

            L 1 Reply Last reply
            0
            • V VCProgrammer

              ok so how can i get its parent disk

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

              Sorry, I'm not sure, but maybe one of these functions[^] will help.

              One of these days I'm going to think of a really clever signature.

              V 1 Reply Last reply
              0
              • L Lost User

                Sorry, I'm not sure, but maybe one of these functions[^] will help.

                One of these days I'm going to think of a really clever signature.

                V Offline
                V Offline
                VCProgrammer
                wrote on last edited by
                #7

                thanks for you help its done...

                L 1 Reply Last reply
                0
                • V VCProgrammer

                  thanks for you help its done...

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

                  Maybe you could give the details here, so it will be available for others facing similar issues.

                  One of these days I'm going to think of a really clever signature.

                  V 1 Reply Last reply
                  0
                  • L Lost User

                    Maybe you could give the details here, so it will be available for others facing similar issues.

                    One of these days I'm going to think of a really clever signature.

                    V Offline
                    V Offline
                    VCProgrammer
                    wrote on last edited by
                    #9

                    using this to get hard disk num of selected drive

                    CString drive_is;//logical drive letter
                    int ret_disk_num=-1;//disk numer of passed logical drive

                    drive\_is.Remove('\\\\');
                    drive\_is.Trim();
                    
                    CString szDrive=\_T("\\\\\\\\.\\\\");
                    szDrive+= drive\_is;
                    
                    	
                    int rt;
                    
                    HANDLE h = CreateFile(szDrive, GENERIC\_READ, FILE\_SHARE\_READ|FILE\_SHARE\_WRITE,NULL,OPEN\_EXISTING,/\*0\*/FILE\_ATTRIBUTE\_NORMAL | FILE\_FLAG\_OVERLAPPED,NULL);
                    if(INVALID\_HANDLE\_VALUE != h)
                    {
                    	VOLUME\_DISK\_EXTENTS vdExtents;
                    	ZeroMemory(&vdExtents, sizeof(vdExtents));
                    
                    	DWORD d =32;
                    				
                    	DWORD dwRet;
                    	rt = DeviceIoControl(h, IOCTL\_VOLUME\_GET\_VOLUME\_DISK\_EXTENTS, NULL, 0, &vdExtents, d, &dwRet, NULL);
                    		
                    	CloseHandle(h);
                    	h=NULL;
                    
                    	if(rt != 0)
                    	{
                    		//vdExtents.Extents\[0\].DiskNumber;
                    
                    		for (DWORD n = 0; n < vdExtents.NumberOfDiskExtents; ++n)
                    		{
                    			PDISK\_EXTENT pDiskExtent = &vdExtents.Extents\[n\];
                    			
                    			ret\_disk\_num =pDiskExtent->DiskNumber;
                    			
                    		}
                    	}
                    	else
                    	{
                    		DWORD d;
                    		d = GetLastError();
                    
                    	}
                    		 	
                    	if(h!=NULL)
                    		CloseHandle(h);
                    }
                    else
                    {
                    	
                    
                    	return ret\_disk\_num;
                    }
                    
                    return ret\_disk\_num;	 
                    

                    }

                    after getting disk drive num chek the media type of drive using Win32_DiskDrive.

                    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