Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Open / Close CD-ROM from Console

Posted on 2004-09-01
2
Medium Priority
?
325 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 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

730 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