Click to See Complete Forum and Search --> : Windows SDK File System: How to get the available logical partitions on my PC?


Andreas Masur
October 2nd, 2004, 03:18 PM
Q: How to get the available logical partitions on my PC?

A:


#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;
}
}
}
}

<br>