如何获得系统光驱的盘符

发表于:2007-06-21来源:作者:点击数: 标签:
Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long 该函数返回系统驱动器类型,返回值为5即为光驱,下面这个例子仅作简单的演示,你可以做进一步的改进以用在您自己的应用程序当中 Private Sub GetCDRomLe

   
  Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

该函数返回系统驱动器类型,返回值为5即为光驱,下面这个例子仅作简单的演示,你可以做进一步的改进以用在您自己的应用程序当中

Private Sub GetCDRomLetter()

Dim DriveNum As Integer
Dim DriveType
Dim CDRom As Integer
Dim DriveLetter As String
Dim i As Byte
DriveNum = 1
Do
DriveNum = DriveNum + 1
DriveLetter = Chr(DriveNum + 65) + ":\"
DriveType = GetDriveType(DriveLetter)
If DriveType = DRIVE_CDROM Then Debug.Print DriveLetter'DRIVE_CDROM=5
Loop Until DriveType = 1'返回值为1,已无可用驱动器

End Sub

原文转自:http://www.ltesting.net