Results 1 to 6 of 6

Thread: POP UP message if there is no media in the CDROM

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    17

    POP UP message if there is no media in the CDROM

    Anybody has code to prompt message if there is no media in the cdrom! (Visual basic or vb script is what I am looking for!)

    Thanks
    Dali

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: POP UP message if there is no media in the CDROM

    This works:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   On Error GoTo trap
    5.     MsgBox Dir("g:")
    6.   Exit Sub
    7. trap:
    8.   If Err.Number = 52 Then
    9.     MsgBox "No disk in drive"
    10.   End If
    11. End Sub

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: POP UP message if there is no media in the CDROM

    Try using FSO:
    VB Code:
    1. Private Sub Command1_Click()
    2. '===============================
    3. Dim fso As New FileSystemObject
    4. Dim drv As Drive
    5.  
    6.     Set drv = fso.GetDrive("e:\")
    7.     If drv.DriveType = CDRom Then
    8.         If drv.IsReady = False Then
    9.             MsgBox "No media found"
    10.         End If
    11.     End If
    12.  
    13. End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    17

    Re: POP UP message if there is no media in the CDROM

    That would work, but in many cases I won't know the drive letter for the cdrom!

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: POP UP message if there is no media in the CDROM

    There can be many Disks that have removeable media. You could just start at "C:" and work your way up, I guess. Check for "\autorun.inf" if it's present, then it's most likely an autorun cd

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: POP UP message if there is no media in the CDROM

    Just loop through drives:
    VB Code:
    1. Private Sub Command1_Click()
    2. '===============================
    3. Dim fso As New FileSystemObject
    4. Dim drv As Drive
    5.  
    6.     For Each drv In fso.Drives
    7.         If drv.DriveType = CDRom Then
    8.             If drv.IsReady = False Then
    9.                 MsgBox "Drive " & drv.DriveLetter & " has no media."
    10.             End If
    11.         End If
    12.     Next drv
    13.  
    14. 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