Solved

Open / Close CD-ROM from Console

Posted on 2004-09-01
2
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

617 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