Pages

Java open cd tray in Windows XP


Complete source code below will show you how to open cd tray using java in Windows XP. I'm not sure whether this code success or not in Vista. I hope someone that use Vista will tell me through comment. It is simple. We will use VBScript code to open cd tray for us. Before i forget, VBScript that will use is VBScript that has related to WSH(Windows Script Host). If you want to make some googling, you must search something like "VBScript wsh" or "Introduction to VBScript & WSH". This is because, if you use only something like "VBScript", you will be bring to page that explain about VBScript in web page development. For someone that interesting in computer virus development, you can try to learn VBScript in wsh. Most of computer virus today is writing using this stuff beside using c,c++,assembly language or others.

PROBLEM IN THIS CODE : How to terminate wscript.exe that left in process tab in windows task manager. Tell me if you know how to solve it in comment box.

*************************************************************
COMPLETE SOURCE CODE FOR : OpenCdTray.java
*************************************************************


import java.awt.Desktop;

import java.io.File;
import java.io.PrintWriter;

public class OpenCdTray
{
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************

//Create a vbscript file called OpenCdTray.vbs
File myCdTrayOpener=new File("OpenCdTray.vbs");

//Create a PrintWriter object that will use to write into created file
PrintWriter pw=new PrintWriter(myCdTrayOpener);

//Write all string in (a) into created file
pw.print(a);

//Flush all resource in PrintWriter to make sure
//there are no data left in this stream.
pw.flush();

//Close PrintWriter and releases any
//system resources associated with it
pw.close();

//Create a Desktop object to open created vbs file(OpenCdTray.vbs).
//It will open using default application that will use
//to handle this file in targeted computer.
//True application to run this file is wscript.exe
Desktop.getDesktop().open(myCdTrayOpener);

//Delete created vbs file before terminate application
myCdTrayOpener.deleteOnExit();
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************
Related Posts Plugin for WordPress, Blogger...

I Also Can Create T-Shirt Logo For You