怎么得到光驅的盤符
發表時間:2023-07-30 來源:明輝站整理相關軟件相關文章人氣:
[摘要]Option ExplicitPrivate Declare Function GetDriveType Lib "kernel32" Alias "GetDriveT...
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