http://www.jinesc.com/myweb/disp.asp?idd=263&room=1020☆获得分区信息并判断是否有CD☆

解决方案 »

  1.   

    您可以使用drive对象
    引用microsoft scripting runtimePrivate Sub Command1_Click()
        Dim fso As New FileSystemObject
        Dim dr As Drive
        
        Set dr = fso.GetDrive("j:")
        If dr.IsReady Then
        Else
            MsgBox "no cd"
        End If
        
    End Sub
      

  2.   

    Declare Function GetVolumeInformation Lib _
    "kernel32" Alias "GetVolumeInformationA" _
    (ByVal lpRootPathName As String, _
    ByVal lpVolumeNameBuffer As String, _
    ByVal nVolumeNameSize As Long, _
    lpVolumeSerialNumber As Long, _
    lpMaximumComponentLength As Long, _
    lpFileSystemFlags As Long, _
    ByVal lpFileSystemNameBuffer As String, _
    ByVal nFileSystemNameSize As Long) As LongDeclare Function GetDriveType Lib "kernel32" _
    Alias "GetDriveTypeA" (ByVal nDrive As String) As LongPublic Const DRIVE_CDROM = 5
    使用:
    Dim VolName As String, FSys As String, erg As Long
    Dim VolNumber As Long, MCM As Long, FSF As Long
    Dim Drive As String, DriveType As Long
    VolName = Space(127)
    FSys = Space(127)
    Drive = "F:\" 'Enter the driverletter you want 
    DriveType& = GetDriveType(Drive$)
    erg& = GetVolumeInformation(Drive$, VolName$, 127&, _
    VolNumber&, MCM&, FSF&, FSys$, 127&)
    Print "分区名称:" & vbTab & VolName$
    Print "序列号:" & vbTab & VolNumber&
    Print "最大文件名称长:" & vbTab & vbTab & MCM&
    Print "文件系统标志:" & vbTab & vbTab & FSF&
    Print "文件系统名称:" & vbTab & FSys$
    Print "类型:" & vbTab & DriveType&;
    'Is the drive a CDROM, if so, check for a CD
    If DriveType& = DRIVE_CDROM Then 
    Print " (CDROM, "; 
    If erg& = 0 Then 
    Print "没有 CD )" 
    Else
    Print "有 CD )" 
    End If
    Else 
    Print " (非 CDROM)"  
    End If