3

Is there a code, I can use that will (once I run it), physically open the cd/dvd drive? I know this is possible in some other languages, but is it possible in Java? Please point me in the correct direction. Thank you

Jeel Shah
  • 3,274
  • 17
  • 47
  • 68

3 Answers3

3

Java provides no way to interact with a cd drive. One easy way on the Windows plateform is to call a VBS script.

Few links which might help you:

Example 1

Example 2

Example 3

Ritesh Mengji
  • 6,000
  • 9
  • 30
  • 46
2

The code to open a CD drive can be even simpler than meain's answer. The .exe file does not need to be copied. It can be run from a command line inside the program :

Runtime.getRuntime().exec("nircmd cdrom open d:");

It should execute and find the nircmd.exe file automatically in the system bin.

chesh
  • 742
  • 8
  • 22
TF777
  • 21
  • 1
0

Check out ninrcmd. It an exe file and has a built in function to open the CD drive.

nircmd.exe cdrom open j: 

and to close it

nircmd.exe cdrom close j: 

To use it add the exe into your program and use this code

Runtime.getRuntime().exec(this.getClass().getResource("nircmd.exe cdrom open j").getPath());
meain
  • 833
  • 9
  • 28