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
Printable View
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
This works:
VB Code:
Option Explicit Private Sub Form_Load() On Error GoTo trap MsgBox Dir("g:") Exit Sub trap: If Err.Number = 52 Then MsgBox "No disk in drive" End If End Sub
Try using FSO:
VB Code:
Private Sub Command1_Click() '=============================== Dim fso As New FileSystemObject Dim drv As Drive Set drv = fso.GetDrive("e:\") If drv.DriveType = CDRom Then If drv.IsReady = False Then MsgBox "No media found" End If End If End Sub
That would work, but in many cases I won't know the drive letter for 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
Just loop through drives:
VB Code:
Private Sub Command1_Click() '=============================== Dim fso As New FileSystemObject Dim drv As Drive For Each drv In fso.Drives If drv.DriveType = CDRom Then If drv.IsReady = False Then MsgBox "Drive " & drv.DriveLetter & " has no media." End If End If Next drv End Sub