Are there any way to know if there is a disc in the cd/dvd-player without searching for any files? Is there a flag set somewhere in windows when a disc is inserted?
Printable View
Are there any way to know if there is a disc in the cd/dvd-player without searching for any files? Is there a flag set somewhere in windows when a disc is inserted?
VB Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long Private Function IsCDInDrive(ByVal strCDDriveLetter As String) As Boolean Dim strStatus As String * 128 'open the device mciSendString "open " & strCDDriveLetter & ": type cdaudio alias cddrive wait", vbNullString, 0, 0 'see if there's something in the drive mciSendString "status cddrive media present", strStatus, Len(strStatus), 0 'close the device mciSendString "close cddrive", vbNullString, 0, 0 'the string will contain "true" or "false" which can be easily converted IsCDInDrive = CBool(Left$(strStatus, InStr(strStatus, vbNullChar) - 1)) End Function
or u can use FSO
VB Code:
Private Sub Command1_Click() Dim fso As New FileSystemObject Dim drv As Drive Set drv = fso.GetDrive("A:") If drv.IsReady Then MsgBox "drive is ready" Else MsgBox "drive not ready" End If End Sub
Thanks! Works great. :-)