API函数GetDriveType:Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long    Dim x
    For x = 97 To 123
        If GetDriveType(Chr(x) + ":") = 5 Then
            MsgBox "This is a CD-ROM : " + Chr(x)
            Exit Sub
        End If
    Next x

解决方案 »

  1.   

    GetDriveType 的用法,参数是什么??
      

  2.   

    用FILESYSTEMOBJECT1、先引用MICROSOFT SCRIPTING RUNTIME
    2、
    Private Sub Command1_Click()
    Dim fs As New FileSystemObject
    Dim Drv As Drive
    Dim DrvLetter As String
    For Each Drv In fs.Drives
        '判断驱动器类型
        If Drv.DriveType =CDROM Then
           DrvLetter = Drv.DriveLetter
           MSGBOX DrvLetter
           EXIT FOR
        NextEnd Sub
      

  3.   


    再给你个例子:Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    Private Sub Form_Load()
        Me.AutoRedraw = True
        Select Case GetDriveType("C:\")
            Case 2
                Me.Print "Removable"
            Case 3
                Me.Print "Drive Fixed"
            Case Is = 4
                Me.Print "Remote"
            Case Is = 5
                Me.Print "Cd-Rom"
            Case Is = 6
                Me.Print "Ram disk"
            Case Else
                Me.Print "Unrecognized"
        End Select
    End Sub
      

  4.   

    GetDriveType 的用法,参数是什么??看用法就知道了!'引用api函数
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long    Dim x
    '循环从A--Z的Acii码,实际上从100开始循环就好,因为C:以前的盘符一般不
    '会是光驱,用do while语句效率会高一些!
        For x = 97 To 123
            'getdrivetype("c:")
            If GetDriveType(Chr(x) + ":") = 5 Then
                MsgBox "This is a CD-ROM : " + Chr(x)
                Exit Sub
            End If
        Next x