2017.07.02 获取系统中所有驱动器的根路径和驱动器属性(版本一)

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

#define BUFSIZE 1024

BOOL GetDriverInfo(LPSTR szDrive);

void main()
{
	CHAR szLogicalDriveStrings[BUFSIZE];
	PCHAR szDrive;
	ZeroMemory(szLogicalDriveStrings,BUFSIZE);
	GetLogicalDriveStrings(BUFSIZE-1, szLogicalDriveStrings);
	szDrive=(PCHAR)szLogicalDriveStrings;
	do
	{
		if(!GetDriverInfo(szDrive))
			printf("\nGet Volume Information Error:%d",GetLastError());
		szDrive+=(lstrlen(szDrive)+1);
	}
	while(*szDrive!='\x00');
}

BOOL GetDriverInfo(LPSTR szDrive)
{
	UINT uDriveType;
	DWORD dwVolumeSerialNumber;
	DWORD dwMaximumComponentLength;
	DWORD dwFileSystemFlags;
	CHAR szFileSystemNameBuffer[BUFSIZE];
	CHAR szDriveName[MAX_PATH];
	printf("\n%s\n",szDrive);
	uDriveType=GetDriveType(szDrive);
	switch(uDriveType)
	{
	case DRIVE_UNKNOWN:
		printf("The drive type cannot be determined.");
		break;
	case DRIVE_NO_ROOT_DIR:
		printf("The root directory does not exist.");
		break;
	case DRIVE_REMOVABLE:
		printf("The disk can be removed from the drive.");
		break;
	case DRIVE_FIXED:
		printf("The disk cannot be removed from the drive.");
		break;
	case DRIVE_REMOTE:
		printf("The drive is a remote (network) drive.");
		break;
	case DRIVE_CDROM:
		printf("The drive is a CD-ROM drive.");
		break;
	case DRIVE_RAMDISK:
		printf("The drive is a RAM disk.");
		break;
	default:
		break;
	}
	if(!GetVolumeInformation(
		  szDrive,        // address of root directory of the 
										 // file system
		  szDriveName,     // address of name of the volume
		  MAX_PATH,         // length of lpVolumeNameBuffer
		  &dwVolumeSerialNumber,  // address of volume serial number
		  &dwMaximumComponentLength,
										 // address of system's maximum 
										 // filename length
		  &dwFileSystemFlags,     // address of file system flags
		  szFileSystemNameBuffer, // address of name of file system
		  BUFSIZE      // length of lpFileSystemNameBuffer
		))
	{
		return false;
	}
	if(0!=lstrlen(szDriveName))
		printf("\nDrive Name is %s\n",szDriveName);
	printf("\nVolume Serial Number is %u",dwVolumeSerialNumber);
	printf("\nMaximum Component Length is %u",dwMaximumComponentLength);
	printf("\nSystem Type is %s\n",szFileSystemNameBuffer);
	if(dwFileSystemFlags & FILE_SUPPORTS_REPARSE_POINTS)
		printf("The file system supports reparse points.\n");
	if(dwFileSystemFlags & FILE_VOLUME_QUOTAS)
		printf("The file system supports disk quotas.\n");
	if(dwFileSystemFlags & FS_CASE_SENSITIVE)
		printf("The file system supports case-sensitive filenames.\n");
	printf("...\n");
	return TRUE;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值