Page 1 of 2

Open CD Drive

Posted: Wed Aug 04, 2010 6:01 pm
by Codex
Hello

This tutorial will tell you how to open and close CD Drive with a simple code.

Ok, so under public class <form name> add this code:
Code: Select all
Private setTrayStatus As Long

    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
     (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
      ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
And then in your button click event or what ever you are using, add this to the click event:

Code: Select all
        'use this code to open the tray
        setTrayStatus = mciSendString("Set CDAudio Door Open", Nothing, 0, 0)

        'use this code to close the tray
        setTrayStatus = mciSendString("Set CDAudio Door Closed", Nothing, 0, 0)
My laptop doesn't close the CD Drive so i don't know if the close code works... i have to close the drive manually...

The project includes some images :D that i got from the internet
Project Download Link:
Open CD Drive.rar
Codexvid

Re: Open CD Drive

Posted: Thu Aug 05, 2010 2:51 am
by zachman61
why not upload it here?
and thanks

Re: Open CD Drive

Posted: Thu Aug 05, 2010 1:33 pm
by Lewis
Thats a nice little tip :) Thanks for this!

Re: Open CD Drive

Posted: Fri Aug 06, 2010 1:38 pm
by Codex
@Zachman61

Sure i will upload it here, if that makes any difference.

codexvid

Re: Open CD Drive

Posted: Fri Aug 06, 2010 1:46 pm
by zachman61
well i just get to much spyware from megaupload and sites like it

Re: Open CD Drive

Posted: Fri Aug 06, 2010 5:47 pm
by XTechVB
Thanks dude

Re: Open CD Drive

Posted: Sat Aug 07, 2010 7:55 am
by Codex
thanks on the comments, glad u liked it.

@Zachman61 - then i will try to upload everything here.

Re: Open CD Drive

Posted: Sat Aug 07, 2010 11:40 am
by Lewis
Zachman i doubt none of our users send spyware

Re: Open CD Drive

Posted: Wed Feb 02, 2011 6:05 am
by elitemusic99
nice code, but the closing code i think is impossible D:

Re: Open CD Drive

Posted: Wed Feb 02, 2011 6:36 am
by Noob.exe
I once made that kind of program on my previous computer (win7) and both opening AND closing worked...