Important alert: (current site time 7/16/2013 4:17:14 AM EDT)
 

VB icon

Close/open the CD Rom door

Email
Submitted on: 6/27/1997
By: Visual Basic On Line User Group  
Level: Beginner
User Rating: By 4 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 58243
 
     Open and close the CD rom door from code! Note:comment out the unneeded api declaration (16 or 32 bit) depending on what operating system you are using!
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Close/open the CD Rom door
'**************************************
'for 16 bit windows
Declare Function mcisendstring Lib "MMSystem" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal wReturnLength As Integer, ByVal hCallback As Integer) As Long
'Note:FOR 95/98/NT using the following:
Public 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
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Close/open the CD Rom door
' Description:Open and close the CD rom door from code! Note:comment out the unneeded api declaration (16 or 32 bit) depending on what operating system you are using!
' By: Visual Basic On Line User Group
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=432&lngWId=1'for details.'**************************************

'to open it:
x= 
mciSendString("set cd door open", 0&, 
0, 0)
'to close it:
x = mciSendString("set 
cd door closed", 0&, 0, 0)


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
6/14/1999 6:04:00 PMChad Muska

This code works perfectly in VB3. No problems with it for me. Good code!
(If this comment was disrespectful, please report it.)

 
8/17/1999 2:36:00 PMReally Dumb Guy

it says it cant find MMSystem.dll Someone like tell me how to Make it so it does Find it please :) i will Make u a Graffic if i can get this dont www.dawgyman.com is my site
(If this comment was disrespectful, please report it.)

 
8/26/1999 8:01:00 PMKyz0r

Here is the correct 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

'to close it:
retvalue = mcisendstring("set CDAudio door closed", returnstring, 127, 0)
'to open it:
retvalue = mcisendstring("set CDAudio door open", returnstring, 127, 0)

This works...

(If this comment was disrespectful, please report it.)

 
9/11/1999 12:39:00 AMJames

This code works fine in VB4 Pro
(If this comment was disrespectful, please report it.)

 
10/23/1999 5:42:00 PMPaperMaker

TO PUT API COMMANDS INTO VB YOU MUST*:
Click Project Menu, select Add Module
Select Module in window that pops up.
Paste the API code right into the Module.
*This is how you do it in VB5 Ent
(If this comment was disrespectful, please report it.)

 
12/17/1999 11:22:11 AMJonathan

I have a question. What API Calls could I use to find out the position of the CDRom door: open/closed?
(If this comment was disrespectful, please report it.)

 
8/4/2000 9:50:36 AMCyberspacer5000@aol.com

i really want this thing to work but i must be doing it wrong i have vb4 32 bit and it isn't working do I open it bye saying Private Sub Command1_Click()
("set cd door open", 0&,
0, 0)
End Sub
? thats what i've been doin' and it didn't seem to work so if someone knows what i did wrong can you please e-mail me at Cyberspacer5000@aol.com and name it Re: the code
thanx
(If this comment was disrespectful, please report it.)

 
8/16/2000 1:09:36 AMChris

This code seems to work:
close it:
retvalue = mcisendstring("set CDAudio door closed", returnstring, 127, 0)
'to open it:
retvalue = mcisendstring("set
CDAudio door open", returnstring, 127,
0)
(If this comment was disrespectful, please report it.)

 
11/15/2000 9:31:39 AMZbi

Ok ! Your code work, but
(If this comment was disrespectful, please report it.)

 
1/27/2003 6:33:12 AM

I really like it!
but the problem is....
I got two CD-Rom drive.
how can I specify the drive to
open/close?
Can you please e-mail me at
drixpanday@yahoo.com, subject: vbcode
(If this comment was disrespectful, please report it.)

 
3/19/2003 5:33:55 PM

How do i get this to work for VB6.0???
(If this comment was disrespectful, please report it.)

 
12/9/2003 8:36:16 AM

Works in VB6, at "3/19/2003 5:33:55 PM": Did you put the declare into a module?
(If this comment was disrespectful, please report it.)

 
9/15/2005 4:01:29 AMerwin castro

very nice code, effective
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.