0
I am using a code to "open/close the disk drawer" however it creates a file on the desktop and would like to arrange some other way to resolve this.
package controller;
import java.awt.Desktop;
import java.io.File;
import java.io.PrintWriter;
public class disc_1 {
public static void main(String[] args) {
try {
//********Start VBScript code to open cd tray************
String a = "Set oWMP = CreateObject(\"WMPlayer.OCX\")" + "\n"
+ "Set colCDROMs = oWMP.cdromCollection" + "\n"
+ "For d = 0 to colCDROMs.Count - 1" + "\n"
+ "colCDROMs.Item(d).Eject" + "\n"
+ "Next" + "\n"
+ "set owmp = nothing" + "\n"
+ "set colCDROMs = nothing" + "\n"
+ "wscript.Quit(0)";
//********End VBScript code to open cd tray************
File myCdTrayOpener = new File("OpenCdTray.vbs");
PrintWriter pw = new PrintWriter(myCdTrayOpener);
pw.print(a);
pw.flush();
pw.close();
Desktop.getDesktop().open(myCdTrayOpener);
myCdTrayOpener.deleteOnExit();
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
//********Start VBScript code to open cd tray************
String a = "Set oWMP = CreateObject(\"WMPlayer.OCX\")" + "\n"
+ "Set colCDROMs = oWMP.cdromCollection" + "\n"
+ "For d = 0 to colCDROMs.Count - 1" + "\n"
+ "colCDROMs.Item(d).Eject" + "\n"
+ "colCDROMs.Item(d).Eject" + "\n"
+ "Next" + "\n"
+ "set owmp = nothing" + "\n"
+ "set colCDROMs = nothing" + "\n"
+ "wscript.Quit(0)";
//********End VBScript code to open cd tray************
File myCdTrayOpener = new File("OpenCdTray.vbs");
PrintWriter pw = new PrintWriter(myCdTrayOpener);
pw.print(a);
pw.flush();
pw.close();
Desktop.getDesktop().open(myCdTrayOpener);
myCdTrayOpener.deleteOnExit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
}
Why don’t you create the file somewhere else (user temp directory maybe?) and then delete it afterwards?
– bfavaretto