首先还是贴代码

VC++ Code:

/* *************************************《精通Windows API》 * 示例代码* GetVolumeInfo.c* 4.2.1    遍历驱动器并获取驱动器属性**************************************//* 头文件 */
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include<string.h>
/* 预定义 */
#define BUFSIZE 1024
/* 函数申明 */
BOOL GetDirverInfo(LPSTR szDrive);/* ************************************* 功能    应用程序主函数,遍历驱动器并调用*            GetDirverInfo 获取驱动器属性**************************************/
void main(void)
{CHAR szLogicalDriveStrings[BUFSIZE];PCHAR szDrive;CHAR lStr;int i ;ZeroMemory(szLogicalDriveStrings,BUFSIZE);// 获取逻辑驱动器卷标名GetLogicalDriveStrings(BUFSIZE - 1,szLogicalDriveStrings);    //strcpy(lStr,szLogicalDriveStrings,sizeof(szLogicalDriveStrings)/sizeof(CHAR));szDrive = (PCHAR)szLogicalDriveStrings;// 循环处理每个卷do{if(!GetDirverInfo(szDrive)){printf("\nGet Volume Information Error: %d", GetLastError());}szDrive += (lstrlen(szDrive)+1);//szDrive = szDrive +lstrlen(szDrive);
    }while(*szDrive!='\x00');scanf("%d",&i);
}/* ************************************* BOOL GetDirverInfo(LPSTR szDrive)* 功能    获取驱动器的属性* 参数    LPSTR szDrive*     指明要获取属性的驱动器的根路径 如 C:\* 返回值 BOOL 是否成功**************************************/
BOOL GetDirverInfo(LPSTR szDrive)
{UINT uDriveType;DWORD dwVolumeSerialNumber;DWORD dwMaximumComponentLength;DWORD dwFileSystemFlags;TCHAR szFileSystemNameBuffer[BUFSIZE];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 path is invalid, for example, no volume is mounted at the path. ");break;case DRIVE_REMOVABLE:printf("The drive is a type that has removable media, for example, a floppy drive or removable hard disk. ");break;case DRIVE_FIXED:printf("The drive is a type that cannot be removed, for example, a fixed hard 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, NULL, 0,&dwVolumeSerialNumber,&dwMaximumComponentLength,&dwFileSystemFlags,szFileSystemNameBuffer,BUFSIZE)){return FALSE;}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 does not support volume mount points.\n");}if(dwFileSystemFlags & FILE_VOLUME_QUOTAS){printf ("The file system supports disk quotas.\n");}if(dwFileSystemFlags & FILE_CASE_SENSITIVE_SEARCH){printf ("The file system supports case-sensitive file names.\n");}//you can use these value to get more informaion////FILE_CASE_PRESERVED_NAMES//FILE_CASE_SENSITIVE_SEARCH//FILE_FILE_COMPRESSION//FILE_NAMED_STREAMS//FILE_PERSISTENT_ACLS//FILE_READ_ONLY_VOLUME//FILE_SUPPORTS_ENCRYPTION//FILE_SUPPORTS_OBJECT_IDS//FILE_SUPPORTS_REPARSE_POINTS//FILE_SUPPORTS_SPARSE_FILES//FILE_UNICODE_ON_DISK//FILE_VOLUME_IS_COMPRESSED//FILE_VOLUME_QUOTASprintf("...\n");return TRUE;
}

编译后运行:

  

vb6 Code(转自网上):

1).类模块中:

Option Explicit'============= 类模块里,名称:GetDiskDrive ===========
'local variable(s) to hold property value(s)
Private mvarDriveCount As Integer 'local copy'Value   Name                  Meaning
'------------------------------------------------------------
'0       DRIVE_UNKNOWN         The drive type cannot be determined.
'1       DRIVE_NO_ROOT_DIR     The root directory does not exist.
'2       DRIVE_REMOVABLE       The disk can be removed from the drive.
'3       DRIVE_FIXED           The disk cannot be removed from the drive.
'4       DRIVE_REMOTE          The drive is a remote (network) drive.
'5       DRIVE_CDROM           The drive is a CD-ROM drive.
'6       DRIVE_RAMDISK         The drive is a RAM disk.
'-------------------------------------------------------------
Public Enum DriveTypeDRIVE_UNKNOWN = 0DRIVE_NO_ROOT_DIR = 1DRIVE_REMOVABLE = 2DRIVE_FIXED = 3DRIVE_REMOTE = 4DRIVE_CDROM = 5DRIVE_RAMDISK = 6
End EnumPrivate drvType(26) As Integer
Private drvName(26) As String
'Attribute drvName.VB_VarDescription = "DriveName"Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveTypeA Lib "kernel32" (ByVal nDrive As String) As LongPublic Function GetDriveType(ByVal n As Integer) As Integer
'Attribute GetDriveType.VB_Description = "获得驱动器类型"GetDriveType = drvType(n)
End FunctionPublic Function GetDriveName(ByVal n As Integer) As String
'Attribute GetDriveName.VB_Description = "获得驱动器名称"GetDriveName = drvName(n)
End FunctionPublic Function GetDriveTypeName(ByVal n As Integer) As StringDim sTypeName As StringSelect Case nCase DRIVE_NO_ROOT_DIRsTypeName = "根目录不存在"Case DRIVE_REMOVABLEsTypeName = "可移动磁盘,如软盘"Case DRIVE_FIXEDsTypeName = "磁盘"Case DRIVE_REMOTEsTypeName = "磁盘映射"Case DRIVE_CDROMsTypeName = "CD-ROM"Case DRIVE_RAMDISKsTypeName = "U盘"Case ElsesTypeName = "未知类型"End SelectGetDriveTypeName = sTypeName
End FunctionPublic Property Let DriveCount(ByVal vData As Integer)
'Attribute DriveCount.VB_Description = "驱动器个数"
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.DriveCount = 5mvarDriveCount = vData
End PropertyPublic Property Get DriveCount() As Integer
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.DriveCountDriveCount = mvarDriveCount
End Property'With this class you can get the systme disk Drive Name and its type
Private Sub Class_Initialize()Dim PathStr As String * 200Dim DriveStr As StringDim L, i As IntegermvarDriveCount = 0If GetLogicalDriveStrings(200, PathStr) <> 0 ThenDriveStr = Mid(PathStr, 1, InStr(1, PathStr, Chr$(0) & Chr$(0)))L = Len(DriveStr)For i = 1 To L Step 4mvarDriveCount = mvarDriveCount + 1drvName(mvarDriveCount) = Mid(DriveStr, i, 3)drvType(mvarDriveCount) = GetDriveTypeA(drvName(mvarDriveCount))Next iEnd If
End Sub

2):窗体中:

Private Sub Command4_Click()Dim i As IntegerDim drv As clsFileSystemAPIDim sResult As StringSet drv = New clsFileSystemAPIsResult = "驱动器总数为:" + CStr(drv.DriveCount) + vbCrLfFor i = 1 To drv.DriveCountsResult = sResult + drv.GetDriveName(i) + vbTab + drv.GetDriveTypeName(drv.GetDriveType(i)) + vbCrLfNext iLabel1.Caption = sResult
End Sub

运行:

  

转载于:https://www.cnblogs.com/xiaoguanqiu/archive/2013/02/26/2933451.html

Windows API 逐个逐个学MessageBox(5) 遍历驱动器并获取驱动器属性 GetLogicalDriveStrings、GetDriveTypeA...相关推荐

  1. [WinAPI] API 5 [遍历驱动器并获取驱动器属性]

    (1) GetLogicalDrives. 获取主机中所有的逻辑驱动器,以BitMap的形式返回. ◇返回值 GetLogicalDrive函数返回一个DWORD类型的值,第一位表示所对应的驱动器是否 ...

  2. FindFirstVolume系列函数遍历驱动器,获取驱动器信息

    什么是"卷"? 卷,又称为"逻辑驱动器",是 NTFS, FAT32 等文件系统组织结构的最高层.卷是存储设备(如硬盘)上由文件系统管理的一块区域,是在逻辑上相 ...

  3. 10、Windows API 文件系统

    一.基本概念 1.磁盘分区(Partitions) 磁盘是装到计算机上的存储设备,比如常见的硬盘.磁盘分区是为了便于管理和使用物理硬盘,而在一个物理硬盘上划分可以各自独立工作的一些逻辑磁盘.比如一块8 ...

  4. Windows API 逐个逐个学(3)----Windows系统基本服务API GetSystemDirectory

    贴代码 VC++ code: 1 /* ************************************ 2 *<精通Windows API> 3 * 示例代码 4 * basic ...

  5. c语言删除文件 Windows,基于Windows API实现遍历所有文件并删除的方法

    本文实例讲述了基于Windows API实现遍历所有文件并删除的方法.分享给大家供大家参考.具体分析如下: 最近一直在学windows API,弄了一些好玩的东西(有点恶作剧了,请大家谨慎使用)... ...

  6. messagebox 全部使用_「一」Windows API 零门槛编程指南——MessageBox

    本篇作为Windows API 系列文章的第一篇,将简要的讲解一下什么是Windows API,Windows API能做些什么,并且尽可能讲解一些新出现的专有名词:本系列博文几乎没有难啃的" ...

  7. 【一】Windows API 零门槛编程指南——MessageBox 基本使用及基础讲解

    本篇作为Windows API 系列文章的第一篇,将简要的讲解一下什么是Windows API,Windows API能做些什么,并且尽可能讲解一些新出现的专有名词:本系列博文几乎没有难啃的" ...

  8. Windows API一日一练(一)第一个应用程序 使用应用程序句柄 使用命令行参数 MessageBox函数 RegisterClass和RegisterClassEx函数

    要跟计算机进行交互,就需要计算机显示信息给人看到,或者发出声音给人听到,然后人看到或听到相应的信息后,再输入其它信息给计算机,这样就可以让计算机进行数据处理,把结果显示给我们.现在就来编写一个最简单的 ...

  9. 《随机出题软件》《随机分队软件》源码(Windows API)

    1 引言 1.1 编写目的: 为了对院级活动<最强大脑>提供软件支持,同时为了练习使用windows API. 1.2 项目背景: 来自计算机学院学生会信息部指派的任务,规定时间完成软件的 ...

最新文章

  1. FSMO角色的Windows界面查看和转移示例
  2. 刘强东:猪飞到天疯狂了十几秒 但摔下死得更快
  3. SpringMVC的请求-获得请求参数-获得基本类型参数
  4. 如何成为优秀的前端工程师
  5. [css] 如何使用css3实现一个div设置多张背景图片?
  6. 好的产品经理都是这样绘制原型图的(下)...
  7. ssh框架http后台乱码问题
  8. C++ 可变索引模板 和 template template
  9. ST Visual Programmer(STVP)给STM8系列芯片烧录程序方法
  10. 简单聊聊什么是Sass、Pass和Iass?
  11. android 生成条码,Android -条形码的生成
  12. LabVIEW基础课程(2) ----虚拟抽奖机
  13. c语言程序数列问题,数列 (C语言代码)
  14. 无人巴士和无人出租车都能用的L4自动驾驶通用硬件方案
  15. 基于数据挖掘的客户流失分析案例
  16. 400+汽车经销商怎么在一天完成算奖?
  17. classList属性配合内置方法add()、remove()、toggle(),添加或删除某个类,以此改变CSS样式
  18. mg90舵机参数_MG995945995舵机的参考资料讲解
  19. 网页中常见的元素有哪些
  20. 深圳计算机网络学校,深圳广外公开学院计算机网络含金量高吗 中专技校学历提升...

热门文章

  1. dart开发Android服务,关于android:在Flutter应用中使用由swagger生成的Dart代码生成的Web服务...
  2. linux修改栈指针x86,x86-堆栈指针未填充16时libc的system()导致分段...
  3. python 如何匹配列表中某个单词_Python中部分指定单词的最佳匹配项
  4. 上传附件_留学落户|上传附件预审时一定一定要注意的问题!
  5. mysql 执行sql error 2,Mysql:执行source sql脚本时,出现:error 2
  6. 崔华 oracle简历,2013数据库大会:崔华-基于Oracle的SQL优化案例分析
  7. kibana 查看索引库中文档个数_百度索引量是什么意思?和百度收录量的区别。...
  8. c语言补全程序,跪求高手解答简单的程序补全题~!
  9. Java 在指定目录中查找文件
  10. SQLServer判断循环