Results 1 to 6 of 6

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
    Try this:

    Code:
    Function CDInDrive() As Boolean
    On Error GoTo ErrHan
      Dir "D:\", vbDirectory
      DiskInDrive = True
    Exit Function
    ErrHan:
    DiskInDrive = False
    End Function
    
    Private Sub Command1_Click()
    
    If CDInDrive() Then
      MsgBox "CD detected"
    Else
      MsgBox "No CD detected"
    End If
    
    End Sub

  3. #3
    Guest
    Origionally by Matt Gates
    Code:
    Function CDInDrive() As Boolean
    On Error GoTo ErrHan
      Dir "D:\", vbDirectory
      DiskInDrive = True
    Exit Function
    ErrHan:
    DiskInDrive = False
    End Function
    
    Private Sub Command1_Click()
    
    If CDInDrive() Then
      MsgBox "CD detected"
    Else
      MsgBox "No CD detected"
    End If
    
    End Sub
    Not good...

    Some people (like me) has D: as a Hard Drive, so it really is a bad idea. Sorry for the correction, but no...

    It'll succeed on D: as CD, but as for E: as CD...

  4. #4
    Guest
    Originally posted by jackbee
    try this

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

    Public Const DRIVE_CDROM = 5

    'Get CD Drive ie D, E etc
    Function GetCDSource() As String
    Dim Srce$
    Dim Index%
    Dim DriveType As Long

    For Index% = Asc("C") To Asc("Z")
    DriveType& = GetDriveType(Chr$(Index%) & ":")
    If DriveType& = DRIVE_CDROM Then
    On Error GoTo NextIndex 'in case CD is empty
    If Len(Dir(Chr$(Index%) & ":\",vbDirectory)) > 0 Then
    Srce$ = Chr$(Index%)
    Exit For
    End If
    End If
    NextIndex:
    Next Index%

    GetCDSource = Srce$

    End Function
    There's a much easier way:

    Code:
      Dim fso As FileSystemObject, d As Object, e As Drives
      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
    No API, and it gets every CD Drive.

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    A question I always wanted to ask:
    do the fso add extra bytes to your project? (DLL needed?)
    and can it run on any windows OS? win9*,win2k,winMe,win98se,winNT?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6
    Guest
    Yes, you have to distribute SCRRUN.DLL. It is not necessary to Place it in the setup file because it is included in VBScript 2.0, but you can call the function in HTML and autodownload VBS2.0. REMEMBER, it's a part of VB Script 2.0.

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