2

How can I close the CD-ROM tray, using Java API or JNI?

Is it possible at all to interact with cd-drive (start burning, stop, make slower or faster rotation, etc)?

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
JaeR
  • 63
  • 3

2 Answers2

1

There is no built-in Java API to do this. The next best thing which people tend to do is to dump a script specific which will open/close the CD drive. This is often done with a VBS script as @Asad Rasheed has commented.

Since you ask for a JNI way of it we will also need to know what platform you are targetting. On Windows, however, you can use mciSendString() with something like:

mciSendString("set cdaudio door open", null, null, null);

If you want more control over which CD drive to open you might want to use some other function such as DeviceIoControl().

Mike Kwan
  • 24,123
  • 12
  • 63
  • 96
0

On Linux/OSX that would be

Runtime.getRuntime().exec("eject");
comrad
  • 105
  • 7