How can I open a CD-Rom device by software ?
Thanks for help !
Michael
Printable View
How can I open a CD-Rom device by software ?
Thanks for help !
Michael
Try the following code in a module / form / class / etc...
'
' Change public to private as appropriate
'
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 EjectCD()
Call mciSendString("set CDAudio Door Open Wait", 0&, 0&, 0&)
End Sub
'
public Sub CloseCD()
Call mciSendString("set CDAudio Door Close Wait", 0&, 0&, 0&)
End Sub
- I don't have a CD on this machine here, but it used to work fine.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
This is good code, but I couldn't it to close the Cd tray. it opened just fine. I'm running NT 4 workstation, any suggestions.
John
John Pirkey
MCSD
www.ShallowWaterSystems.com
'
' Change public to private as appropriate
'
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 EjectCD()
Call mciSendString("set CDAudio Door Open", 0&, 0&, 0&)
End Sub
'
Public Sub CloseCD()
Call mciSendString("set cdAudio Door Closed", 0&, 0&, 1&)
End Sub
You'll notice, all I did was take out the waits ( It will probably work with them in though) and changed the last parameter from 0& to 1&, Presto! closing cdrom door!
I'm an idiot!!!
In Chris Eastwoods example everything was exactly correct, except, his close string was "set CDAudio Door Close Wait" it should have been "set CDAudio Door Closed Wait"
That is the only change that needs to be made, no 0's to 1's or none of that crap. I'm just an idiot! ......(walks off mumbling shaking head) :-)
Thank you! That was it, add the "d" to "close".
John
John Pirkey
MCSD
www.ShallowWaterSystems.com