windows API 获取磁盘信息

GetLogicalDriveStrings - 获取系统中存在的逻辑驱动器字符串
GetLogicalDriveStrings(
nBufferLength: DWORD; {缓冲区大小}
lpBuffer: PAnsiChar {缓冲区}
): DWORD;

获取磁盘名称填充到lpbuffer.
GetVolumeInformation - 读取文件系统信息
GetVolumeInformation(
lpRootPathName: PChar; {磁盘驱动器代码字符串}
lpVolumeNameBuffer: PChar; {磁盘驱动器卷标名称}
nVolumeNameSize: DWORD; {磁盘驱动器卷标名称长度}
lpVolumeSerialNumber: PDWORD; {磁盘驱动器卷标序列号}
var lpMaximumComponentLength: DWORD; {系统允许的最大文件名长度}
var lpFileSystemFlags: DWORD; {文件系统标识}
lpFileSystemNameBuffer: PChar; {文件操作系统名称}
nFileSystemNameSize: DWORD {文件操作系统名称长度}
): BOOL;
GetDiskFreeSpaceEx - 获取磁盘容量信息
BOOL GetDiskFreeSpace(
LPCTSTR lpRootPathName,
LPDWORD lpSectorsPerCluster,
LPDWORD lpBytesPerSector,
LPDWORD lpNumberOfFreeClusters,
LPDWORD lpTotalNumberOfClusters
);


==================================================================================================

#include #include void getType(char *); int main(int argc, char** args) { char dwPath[MAX_PATH] = { 0 }; char* p = dwPath; GetLogicalDriveStrings(MAX_PATH - 1, dwPath); int s = strlen(dwPath); do {CHAR volumeNmaeBuff[MAX_PATH]; DWORD volumeSerialNumber; DWORD maximumComponentLength; DWORD fileSystemFlag; CHAR fileSystemName[MAX_PATH]; //getType(p); if (GetVolumeInformation(p, volumeNmaeBuff, MAX_PATH, &volumeSerialNumber, &maximumComponentLength, &fileSystemFlag, fileSystemName, MAX_PATH)) { printf("\r\n==========================================================\r\n"); printf("%s\r\n", p); if (strlen(volumeNmaeBuff)!=0) { printf("驱动器卷标:%s\r\n", volumeNmaeBuff); } printf("驱动器序列号:%lu\r\n\ 最大文件名长度:%u\r\n\ 文件系统标识:%u\r\n\ 文件系统类型:%s\r\n", volumeSerialNumber, maximumComponentLength, fileSystemFlag, fileSystemName); } else {return FALSE; }p += (s+1); } while (*p!='\x00'); system("pause"); return 0; }void getType(char * str) { UINT uTYPE; uTYPE = GetDriveType(str); switch (uTYPE) { case DRIVE_UNKNOWN: printf("%s未知磁盘类型\r\n", str); break; case DRIVE_NO_ROOT_DIR: printf("%s无效盘符\r\n", str); break; case DRIVE_REMOVABLE: printf("%s移动磁盘\r\n", str); break; case DRIVE_FIXED: printf("%s固定磁盘\r\n", str); break; case DRIVE_REMOTE: printf("%s网络磁盘\r\n", str); break; case DRIVE_CDROM: printf("%s光驱\r\n", str); break; case DRIVE_RAMDISK: printf("%sRAM磁盘\r\n", str); default: break; } }



【windows API 获取磁盘信息】

    推荐阅读