Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const DRIVE_CDROM = 5
Public Function GetCDRom() As String
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
GetCDRom = Left(UCase(JustOneDrive), 2)
Exit Do
End If
End If
Loop Until AllDrives = "" Or rtn = DRIVE_CDROM
If GetCDRom = "" Then
MsgBox "没有光驱"
Else
Call ShellExecute(hwnd, "Open", "", "", GetCDRom, 1)
End If
End Function
[此贴子已经被作者于2007-3-18 20:48:50编辑过]
|