检测磁盘类型的信息
【打印文章】
作者:土人
磁盘类型的检测是很有意义的。比如,安装程序要懂得用户所指定的磁盘是否为硬盘,不是则予以提示;又比如,要自动播放光盘中的音频文件或影视文件,首先得判断光驱的驱动器号才得以实现。那么,如何检测磁盘的类型呢?
Windows的GetDriveType函数就是为获取磁盘类型而准备的,利用它可以轻而易举地得到我们所需的磁盘类型信息。以下以一个简单的例子展示获取压缩盘以外的常规磁盘的类型这一有用的技术:
Option Explicit
'申明API函数
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub Form_Load()
'声明变量
Dim DrvNum As Single
Dim drvName As String
Dim DrvType As Integer
Dim i As Integer
Me.AutoRedraw = True
Drive1.Visible = False
'获取所有常规磁盘信息——
DrvNum = Asc("a") - 1
For i = 0 To Drive1.ListCount
DrvNum = DrvNum + 1
drvName = Chr(DrvNum) + ":\"
DrvType = GetDriveType(drvName)
Select Case GetDriveType(drvName)
Case 0
Me.Print "不明 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 2
Me.Print "软驱 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 3
Me.Print "硬盘 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 4
Me.Print "网络盘 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 5
Me.Print "光驱 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 6
Me.Print "RamDisk " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
End Select
Next i
End Sub
磁盘类型的检测是很有意义的。比如,安装程序要懂得用户所指定的磁盘是否为硬盘,不是则予以提示;又比如,要自动播放光盘中的音频文件或影视文件,首先得判断光驱的驱动器号才得以实现。那么,如何检测磁盘的类型呢?
Windows的GetDriveType函数就是为获取磁盘类型而准备的,利用它可以轻而易举地得到我们所需的磁盘类型信息。以下以一个简单的例子展示获取压缩盘以外的常规磁盘的类型这一有用的技术:
Option Explicit
'申明API函数
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub Form_Load()
'声明变量
Dim DrvNum As Single
Dim drvName As String
Dim DrvType As Integer
Dim i As Integer
Me.AutoRedraw = True
Drive1.Visible = False
'获取所有常规磁盘信息——
DrvNum = Asc("a") - 1
For i = 0 To Drive1.ListCount
DrvNum = DrvNum + 1
drvName = Chr(DrvNum) + ":\"
DrvType = GetDriveType(drvName)
Select Case GetDriveType(drvName)
Case 0
Me.Print "不明 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 2
Me.Print "软驱 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 3
Me.Print "硬盘 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 4
Me.Print "网络盘 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 5
Me.Print "光驱 " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
Case 6
Me.Print "RamDisk " + "盘符为: " + Trim(UCase(Chr(DrvNum)))
End Select
Next i
End Sub
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】