获取硬盘分区信息

  /*
 * 硬盘分区序列号
 * [email protected] 2007.5.28
 */
#include
#include
#include
int main() {
 _ULARGE_INTEGER lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
 DWORD serialNumber, maxComponentLength, fsFlags;
 TCHAR szFileSystem[12];
 TCHAR szVolumeName[24];
 TCHAR szRoot[4] = "c:\\";
  
 if (!GetVolumeInformation(
  szRoot,
  szVolumeName,
  sizeof(szVolumeName),
  &serialNumber,
  &maxComponentLength,
  &fsFlags,
  szFileSystem,
  sizeof(szFileSystem))) {
  printf("Failed to retrieve drive information\n");
 }
 GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes);
 //根据MSDN的说明,如果分区大于2G一定要用GetDiskFreeSpaceEx

 printf("卷标: %s\n分区类型: %s\n卷序列号: %04X-%04X\n",
  szVolumeName,
  szFileSystem,
  serialNumber >> 16,
  serialNumber & 0xFFFF
  );
 printf("分区总空间大小: %d MB\n",lpTotalNumberOfBytes.QuadPart / (1024 *1024));
 printf("分区剩余空间大小: %d MB\n",lpTotalNumberOfFreeBytes.QuadPart / (1024 *1024));
 printf("调用者可用的空间大小: %d MB\n",lpFreeBytesAvailableToCaller.QuadPart / (1024 *1024));
 return(0);
}

你可能感兴趣的:(获取硬盘分区信息)