#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#define BUFSIZE 1024
BOOL GetDriveInfo(LPSTR szDrive){
UINT uDriveType;
uDriveType=GetDriveType(szDrive);//返回一个数字表示磁盘类型,如下:
//#define DRIVE_UNKNOWN 0 //未知
//#define DRIVE_NO_ROOT_DIR 1 //传入的磁盘字符串非根目录
//#define DRIVE_REMOVABLE 2 //移动硬盘
//#define DRIVE_FIXED 3 //硬盘
//#define DRIVE_REMOTE 4 //远程驱动器
//#define DRIVE_CDROM 5 //光盘
//#define DRIVE_RAMDISK 6 //U盘
printf("%s\n",szDrive);
switch(uDriveType){
case DRIVE_UNKNOWN:
printf("未知磁盘\n");
break;
case DRIVE_NO_ROOT_DIR:
printf("非根目录\n");
break;
case DRIVE_REMOVABLE:
printf("移动硬盘\n");
break;
case DRIVE_FIXED:
printf("硬盘\n");
break;
case DRIVE_REMOTE:
printf("远程驱动器\n");
break;
case DRIVE_CDROM:
printf("光盘\n");
break;
case DRIVE_RAMDISK:
printf("U盘\n");
break;
}
//返回更对的磁盘属性信息
CHAR dzDriveName[MAX_PATH];
DWORD dwVolumeSerialNumber;
DWORD dwMaximumComponentLength;
DWORD dwFileSystemFlags;//得到一个数字,需要根据常量来判断
CHAR szFileSystemNameBuffer[MAX_PATH];
if(!GetVolumeInformation(szDrive,
dzDriveName,//驱动器名
MAX_PATH,//驱动器名长度
&dwVolumeSerialNumber,//硬盘序列号
&dwMaximumComponentLength,//允许的文件名最大长度
&dwFileSystemFlags,//更多信息,需要根据常量来判断
szFileSystemNameBuffer,//文件系统名称
MAX_PATH//文件系统名称长度
)){
return FALSE;
};
if(0!=lstrlen(dzDriveName)){//如果有卷标则输出
printf("%s\n",dzDriveName);
}
printf("硬盘序列号%u\n",dwVolumeSerialNumber);
printf("允许的文件名最大长度%d\n",dwMaximumComponentLength);
printf("文件系统名称%s\n",szFileSystemNameBuffer);
printf("更多信息%d\n",dwFileSystemFlags);
//更多信息的全部常量如下:
//#define FILE_SHARE_READ 0x00000001
//#define FILE_SHARE_WRITE 0x00000002
//#define FILE_SHARE_DELETE 0x00000004
//#define FILE_ATTRIBUTE_READONLY 0x00000001
//#define FILE_ATTRIBUTE_HIDDEN 0x00000002
//#define FILE_ATTRIBUTE_SYSTEM 0x00000004
//#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
//#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
//#define FILE_ATTRIBUTE_DEVICE 0x00000040
//#define FILE_ATTRIBUTE_NORMAL 0x00000080
//#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
//#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
//#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
//#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
//#define FILE_ATTRIBUTE_OFFLINE 0x00001000
//#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
//#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
//#define FILE_ATTRIBUTE_VIRTUAL 0x00010000
//#define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
//#define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
//#define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
//#define FILE_NOTIFY_CHANGE_SIZE 0x00000008
//#define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
//#define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
//#define FILE_NOTIFY_CHANGE_CREATION 0x00000040
//#define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
//#define FILE_ACTION_ADDED 0x00000001
//#define FILE_ACTION_REMOVED 0x00000002
//#define FILE_ACTION_MODIFIED 0x00000003
//#define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
//#define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
//#define MAILSLOT_NO_MESSAGE ((DWORD)-1)
//#define MAILSLOT_WAIT_FOREVER ((DWORD)-1)
//#define FILE_CASE_SENSITIVE_SEARCH 0x00000001
//#define FILE_CASE_PRESERVED_NAMES 0x00000002
//#define FILE_UNICODE_ON_DISK 0x00000004
//#define FILE_PERSISTENT_ACLS 0x00000008
//#define FILE_FILE_COMPRESSION 0x00000010
//#define FILE_VOLUME_QUOTAS 0x00000020
//#define FILE_SUPPORTS_SPARSE_FILES 0x00000040
//#define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
//#define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
//#define FILE_VOLUME_IS_COMPRESSED 0x00008000
//#define FILE_SUPPORTS_OBJECT_IDS 0x00010000
//#define FILE_SUPPORTS_ENCRYPTION 0x00020000
//#define FILE_NAMED_STREAMS 0x00040000
//#define FILE_READ_ONLY_VOLUME 0x00080000
//#define FILE_SEQUENTIAL_WRITE_ONCE 0x00100000
//#define FILE_SUPPORTS_TRANSACTIONS 0x00200000
//#define FILE_SUPPORTS_HARD_LINKS 0x00400000
//#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES 0x00800000
//#define FILE_SUPPORTS_OPEN_BY_FILE_ID 0x01000000
//#define FILE_SUPPORTS_USN_JOURNAL 0x02000000
if(dwFileSystemFlags & FILE_VOLUME_QUOTAS){//是否启用了配额
printf("支持配额\n");
}
return TRUE;
}
int main(){
GetDriveInfo(TEXT("C:\\"));
system("pause");
return 0;
}
|