#include <stdio.h> #include <stdlib.h> #include <windows.h>
#define BUFSIZE 1024
BOOL GetDirverInfo(LPSTR szDriver);
void main() { CHAR szLogicalDriverStrings[BUFSIZE] = {0}; PCHAR szDriver = NULL; ZeroMemory(szLogicalDriverStrings,BUFSIZE); GetLogicalDriveStrings( (BUFSIZE - 1),szLogicalDriverStrings); szDriver = (PCHAR) szLogicalDriverStrings; do { if ( ! GetDirverInfo(szDriver) ) { printf("\n得到卷信息错误:%d",GetLastError() ); } szDriver += ( lstrlen(szDriver) + 1 ); } while (*szDriver != '\x00');
getchar(); }
BOOL GetDirverInfo(LPSTR szDriver) { UINT nDriverType; CHAR szDriverName[MAX_PATH]; DWORD nVolumeSerialNumber; DWORD nMaximumComponentLength; DWORD nFileSystemFlags; CHAR szFileSystemNameBuffer[MAX_PATH]; nDriverType = GetDriveType(szDriver); switch (nDriverType) { case DRIVE_UNKNOWN: printf("%s","未知的驱动器"); break; case DRIVE_NO_ROOT_DIR: printf("%s","根路径无效驱动器"); break; case DRIVE_REMOVABLE: printf ("%s","可插拔的驱动器"); break; case DRIVE_CDROM: printf("%s","光驱驱动"); break; case DRIVE_RAMDISK: printf("%s","硬盘驱动"); break; default: printf("%s","其他类型"); }
if ( !GetVolumeInformation( szDriver, szDriverName, MAX_PATH, &nVolumeSerialNumber, &nMaximumComponentLength, &nFileSystemFlags, szFileSystemNameBuffer, BUFSIZE ) ) { goto EXIT0; } if ( 0 != lstrlen(szDriverName) ) { printf("\n驱动器名字 是 %s\n",szDriverName); } printf("\n 卷的序列号是 %u\n",nVolumeSerialNumber); printf("\n 最大元件长度是 %u\n",nMaximumComponentLength); printf("\n 文件系统类型是 %s\n",szFileSystemNameBuffer);
return true; EXIT0:
return false; }
|