HardDisk0 Volume0 (C:) Volume1 (D:)HardDisk1 Volume0 (E:)
#include <iostream>#include <stdio.h>#include <windows.h>#include <winioctl.h>using namespace std;#define BUFSIZE 1024int main(){ DWORD drives = GetLogicalDrives(); TCHAR path[] = {'\\', '\\', '.', '\\', 0, ':', 0}; PVOLUME_DISK_EXTENTS volume = (PVOLUME_DISK_EXTENTS)new char[BUFSIZE]; DWORD size; HANDLE hFile; for (char c = 0; c < 26; c++) { if (drives & (1 << c)) { path[4] = c + 0x61; hFile = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, 0, 0); if (hFile != INVALID_HANDLE_VALUE) { DeviceIoControl(hFile, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, 0, 0, volume, BUFSIZE, &size, 0); CloseHandle(hFile); if (size > 0) { for (DWORD n = 0; n < volume->NumberOfDiskExtents; n++) printf(TEXT("HardDisk%u: %s\n"), volume->Extents[n].DiskNumber, path); } } } } delete []volume;}
Harddisk0 Partition1 (\ Device \ HarddiskVolume1) D: Partition2 (\ Device \ HarddiskVolume2) C: