Jim Lawless' Blog


A Command-Line CD Tray Opener

Originally published on: Thu, 20 Aug 2009 02:30:38 +0000

I needed a command-line utility for Windows that would open or close the CD tray. The result is cdctrl.exe. Please refer to the C source code below.

cdctrl.c


// cdctrl
// A command-line CD-ROM tray opener/closer.
//
// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.


#include <windows.h>
#include <stdio.h>
#include <ctype.h>
 
#pragma comment(lib, "winmm.lib")
 
void syntax(void);

int main(int argc,char **argv) {
   if(argc<2) {
      syntax();
      return 1;
   }
   if(toupper(*argv[1])=='O') {
      mciSendString("set CDAudio door open wait",0,0,0);
   }
   else
   if(toupper(*argv[1])=='C') {
      mciSendString("set CDAudio door closed",0,0,0);
   }
   else {
      syntax();
      return 1;
   }
   return 0;
}

void syntax(void) {
   printf("Syntax:\n\tcdctrl open\nor\n\tcdctrl close\n");
}

If you execute the above program with no arguments, you should see the following: Syntax: cdctrl open or cdctrl close

The source code and EXE for the cdctrl can be found here:

http://www.mailsend-online.com/wp/cdctrl.zip

Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless

del_icio_us Save to del.icio.us
stumbleupon Save to StumbleUpon
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks



Previous post: Java in a Windows EXE with launch4j
Next post:Tracing XSLT with a Tiny Java Web Server


Search this Blog (and site)

Search this Site with PicoSearch


Subscribe to this Blog

 Subscribe!


Contact Me

Email: jimbo@radiks.net


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

Mad Schemes : Learning Lisp via SICP

Auto Save Clipboard Images Redux

Extending SpiderMonkey JavaScript on Windows

Rhino JavaScript to EXE with launch4j

Compiling Rhino JavaScript to Java

Directory Traversal in Rhino JavaScript

Taking Shape

We've Moved!


Popular Posts

A Command-Line MP3 Player for Windows

Auto Save Images from the Clipboard

Java in a Windows EXE with launch4j

An Interview with Tom Zimmer: Forth System Developer

Setting Windows Console Text Colors in C


Random Posts

An Interview with the Creator of the BDS C Compiler

CP/M Days

PHP, Transparent GIF's, and Web Tracking

Command-Line Image Format Conversion

A Quine in Forth

A Quine in C

Java in a Windows EXE with launch4j

Twimmando: A Command-line Twitter Client

Mad Schemes : Learning Lisp via SICP

Preventing Windows Screen-Saver Activation


Full List of Posts

http://www.mailsend-online.com/bloglist.htm


Blogroll

MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer