怎么得到光驅(qū)的盤符
發(fā)表時(shí)間:2023-07-30 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]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-->獲取一個(gè)字串,其中包含了當(dāng)前所有邏輯驅(qū)動器的根驅(qū)動器路徑
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) 注釋:設(shè)置緩沖
rtn = GetLogicalDriveStrings(Len(AllDrives), AllDrives) 注釋:調(diào)用函數(shù)得到包含所有驅(qū)動器的字符串
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) 注釋:檢查驅(qū)動器類型
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 = "沒有發(fā)現(xiàn)光驅(qū)!"
End If
End Sub