Sunday, August 2, 2009

Open and Close CDROM using vb6

To open and close of CDROM with vb6, you please make beforehand new module, afterwards insert code following :

Option Explicit
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

Public Sub OpenCDROM()
retvalue = mciSendString("set CDAudio door open", _
returnstring, 127, 0)
End Sub

Public Sub CloseCDROM()
retvalue = mciSendString("set CDAudio door closed", _
returnstring, 127, 0)
End Sub

Example Open and Close CDROM:
  • Open CDROM
    Call OpenCDROM
  • Close CDROM
    Call CloseCDROM


  1. Good Post.
    Dim returnstring As String
    Dim retvalue As Integer

    Variables are not defined pls define it.