Results 1 to 3 of 3

Thread: How can I exam if there is CD in CDROM

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Location
    China
    Posts
    25

    Question

    How can I exam if there is CD in CDROM
    I have examed in this way:

    On Error Goto NOCD
    ...............
    Dir "E:\aaa.aaa"
    Msgbox "CD In CDROM"
    Exit Sub
    NOCD:
    Msgbox "No CD In CDROM"
    Exit Sub

    But if the fuction is to long,I don't thibk it can work well.
    How can I exam it in a "normal" way? API?

  2. #2
    Guest
    Here you go:

    Code:
      Dim fso As FileSystemObject, d As Object, e As Drives, i As Byte
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set e = fso.Drives
      For Each d In e
        If d.DriveType = 4 Then
            If d.isready = True Then
                MsgBox "CD-Rom " & d.DriveLetter & ": is Ready."
            Else
                MsgBox "CD-Rom " & d.DriveLetter & ": is Not Ready."
            End If
         End If
      Next

  3. #3
    Member
    Join Date
    Oct 2000
    Location
    Belgrade,Yugoslavia
    Posts
    34
    Here is a tip from vb-world's tips section :

    Retrieving Volume Information and checking if a CD is in the drive

    This tip demonstrates how you can receive lots of information about a drive, including the Volume name and number. You can also retrieve information about the type of drive (hard disk, cdrom, removable, etc.)

    Module Code

    Add the following code to a module:

    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 Long

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

    Public Const DRIVE_CDROM = 5
    Form Code

    Add one command button to a form with the following code:

    Private Sub Command1_Click()

    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 "VolumeName:" & vbTab & VolName$
    Print "VolumeNumber:" & vbTab & VolNumber&
    Print "MCM:" & vbTab & vbTab & MCM&
    Print "FSF:" & vbTab & vbTab & FSF&
    Print "FileSystem:" & vbTab & FSys$
    Print "DriveType:" & 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 "no CD in the drive)"
    Else
    Print "CD in the drive)"
    End If

    Else

    Print " (NO CDROM)"

    End If

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width