怎样得到光驱的盘符?

王朝vb·作者佚名  2006-01-08
宽屏版  字体: |||超大  

Option Explicit

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _

(ByVal nDrive As String) As Long

'GetLogicalDriveStrings-->获取一个字串,其中包含了当前所有逻辑驱动器的根驱动器路径

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" _

(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Const DRIVE_REMOVABLE = 2

Private Const DRIVE_FIXED = 3

Private Const DRIVE_REMOTE = 4

Private Const DRIVE_CDROM = 5

Private Const DRIVE_RAMDISK = 6

Private Sub Command1_Click()

Dim rtn As String

Dim AllDrives As String

Dim JustOneDrive As String

AllDrives = Space$(64) '设置缓冲

rtn = GetLogicalDriveStrings(Len(AllDrives), AllDrives) '调用函数得到包含所有驱动器的字符串

AllDrives = Left(AllDrives, rtn)

Do

rtn = InStr(AllDrives, Chr(0))

If rtn Then '若有的话

JustOneDrive = Left(AllDrives, rtn)

AllDrives = Mid(AllDrives, rtn + 1, Len(AllDrives))

rtn = GetDriveType(JustOneDrive) '检查驱动器类型

If rtn = DRIVE_CDROM Then '是CD-ROM

Label1.Caption = Left(UCase(JustOneDrive), 2) '给label1

Exit Do

End If

End If

Loop Until AllDrives = "" Or rtn = DRIVE_CDROM

Command1.Enabled = False

If Label1.Caption = "" Then

Label1.Caption = "没有发现光驱!"

End If

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有