CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Windows SDK File System: How to get the available logical partitions on my PC?

    Q: How to get the available logical partitions on my PC?

    A:

    Code:
    #include <iostream>
    
    // Get logical drives
    DWORD dwLogicalDrives = ::GetLogicalDrives();
    if(dwLogicalDrives)
    {
      for(int iCnt = 0; iCnt < 32; ++iCnt)
      {
        memset(szDriveRoot, 0, sizeof(szDriveRoot));
    
        if(dwLogicalDrives & (1 << iCnt))
        {
          // Set drive root
          sprintf(szDriveRoot, "%c:\\", iCnt + 'A');
    
          // Determine partition type
          UINT uiDriveType = ::GetDriveType(szDriveRoot);
    
          switch(uiDriveType)
          {
            // Unknown
            case DRIVE_UNKNOWN:
              std::cout << "Partition " << szDriveRoot << " -> " << "Unknown" << std::endl;
              break;
    
            // Root path invalid
            case DRIVE_NO_ROOT_DIR:
              std::cout << "Partition " << szDriveRoot << " -> " << "Root path invalid"
                        << std::endl;
              break;
    
            // Removable drive
            case DRIVE_REMOVABLE:
              std::cout << "Partition " << szDriveRoot << " -> " << "Removable drive"
                        << std::endl;
              break;
    
            // Fixed drive
            case DRIVE_FIXED:
              std::cout << "Partition " << szDriveRoot << " -> " << "Fixed drive"
                        << std::endl;
              break;
    
            // Network drive
            case DRIVE_REMOTE:
              std::cout << "Partition " << szDriveRoot << " -> " << "Network drive"
                        << std::endl;
              break;
    
            // CD-ROM
            case DRIVE_CDROM:
              std::cout << "Partition " << szDriveRoot << " -> " << "CD-ROM"
                        << std::endl;
              break;
    
            // RAM-Disk
            case DRIVE_RAMDISK:
              std::cout << "Partition " << szDriveRoot << " -> " << "RAM-Disk"
                        << std::endl;
              break;
          }
        }
      }
    }
    Last edited by Andreas Masur; July 24th, 2005 at 05:22 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured