Solved

Open / Close CD-ROM from Console

Posted on 2004-09-01
2
305 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 300 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

820 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