Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Open / Close CD-ROM from Console

Posted on 2004-09-01
2
Medium Priority
?
328 Views
Last Modified: 2012-06-27
What is the easiest way to open / close a CD-ROM from the console?  

Regards,
Tony
0
Comment
Question by:fattumsdad
2 Comments
 
LVL 5

Accepted Solution

by:
danielsonchris earned 1200 total points
ID: 11958653
What OS?  
If we are talking *nux just use
`eject`
and
`eject -t`
to retract.

If windows then using C++ (since this is the C++ forum):

#include "mmsystem.h"      // For mci functions
#include <stdio.h>            // For printf()

//call like Win32Eject(TRUE, 'E');     To eject drive E
//           Win32Eject(FALSE, 'E');     To retract drive E
void Win32Eject(BOOL bOpenDrive, TCHAR cDrive)
{
      MCI_OPEN_PARMS op;
      MCI_STATUS_PARMS st;
      DWORD flags;

      TCHAR szDriveName[4];
      strcpy(szDriveName, "X:");

      ::ZeroMemory(&op, sizeof(MCI_OPEN_PARMS));
      op.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_CD_AUDIO;
      
      if(cDrive > 1)
      {
            szDriveName[0] = cDrive;
            op.lpstrElementName = szDriveName;
            flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE;
      }
      else flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE;

      if (!mciSendCommand(0,MCI_OPEN,flags,(unsigned long)&op))
      {
            st.dwItem = MCI_STATUS_READY;

            if(bOpenDrive)
                  mciSendCommand(op.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0);
            else
                  mciSendCommand(op.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);

            mciSendCommand(op.wDeviceID,MCI_CLOSE,MCI_WAIT,0);
      }
}

you can take the above code and then create a console program (eject.exe).  From there you can script the CD Door opening and closing.
Peace,
Chris
0
 
LVL 8

Expert Comment

by:pjcrooks2000
ID: 11958939
Aye looks a good idea to me :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question