Jeel Shah
Jeel Shah

Reputation: 3334

How to open cd drive java

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

Upvotes: 3

Views: 11306

Answers (3)

TF777
TF777

Reputation: 21

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.

Upvotes: 2

meain
meain

Reputation: 861

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());

Upvotes: 0

Ritesh Mengji
Ritesh Mengji

Reputation: 6190

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

Upvotes: 3

Related Questions