Open CD tray using JNA in Java

I know this is about JNA and not JNI, but I couldn't find a better forum to place this. And since JNA builds upon JNI, I thought I would give it a try here.
I was looking for a while to figure out how to open the CD tray using Java on Windows. After a while I came up with this solution:
1. Download the jna library (jna.rar) from [https://jna.dev.java.net/|https://jna.dev.java.net/]
2. Add this to your project (in NetBeans right click the Libraries folder in the Project view and click Add JAR/Folder, then locate the jna.jar file and add this).
3. Then, make a new Java class and name it WinMM.java, and add the following code to that file
import com.sun.jna.Library;
import com.sun.jna.Native;
interface WinMM extends Library { /* We'll make a new library */
    WinMM INSTANCE = (WinMM) Native.loadLibrary(("winmm"), WinMM.class); //Create the library from the winmm.dll file
    long mciSendStringA(String lpstrCommand, String lpstrReturnString, long uReturnLength, long hwndCallback); //Create the function we need to use to open the CD tray
}4. Now you can add the following code into a button event in another class in your app to open the CD tray:
WinMM.INSTANCE.mciSendStringA("set CDAudio door open", null, 0, 0);5. Or to close the tray:
WinMM.INSTANCE.mciSendStringA("set CDAudio door closed", null, 0, 0);6. A simple app, which opens and closes the CD tray, would look like this:
public class Main {
     * @param args the command line arguments
    public static void main(String[] args) {
    WinMM.INSTANCE.mciSendStringA("set CDAudio door open", null, 0, 0); //Open tray
    WinMM.INSTANCE.mciSendStringA("set CDAudio door closed", null, 0, 0); //Close tray
}I hope this will save someone some hours of googling. And if you really don't want to use JNA, there is a solution in [this thread|http://forum.java.sun.com/thread.jspa?threadID=566946&messageID=4103195] which might work just as well. I haven't tested it though.

Hi Svenni, thanks for your wonderful post! If you don't mind, I have a few questions on this. Plus, if you are feeling generous, then perhaps you could even advise me on another related topic.
To start, I set up this WinMM library exactly as you prescribed, but it doesn't seem to work for me. I think I am doing everything correct, as Netbeans didn't complain about me using any
of the classes in the jna.jar file. Everything compiles just fine, so I think I am calling everything correctly.
I thought that maybe my drive isn't being acknowledged as "cdaudio", and my goal isn't to open the drive anyways. So, I found the list of MCI commands here:
[MCI commands|http://msdn.microsoft.com/en-us/library/ms712587(VS.85).aspx]
And tried to do this:
WinMM.INSTANCE.mciSendStringA("set waveaudio audio all off", null, 0, 0);Which it seems would deactivate all audio on my system, but it does not. Unfortunately, there are no errors being thrown by doing any of this, so I really don't know where to look.
What I am trying to accomplish is to gain control of the analog volume controls. The Java Sound API apparently used to support this, but it does not seem to anymore.
I can create Source and Target data lines, and read and write to them with no problems, but for some reason I am not able to get ANY controls on any line! It does seem to
be the consensus that you can't control the analog mixer from Java, and that's why I have been researching other avenues. This has been one of them, but I just can't seem to get
it to work. I think if I could, then my problems may be solved. Well, all but the problem that the MCI command strings don't seem to have support for mute/unmute, but I may have to
deal with that seperately. In my app at the moment, I basically shell execute "sysvol32.exe -R" and leave it up to my user to set the recording level, but I'd really like to manage that through
software.
Any suggestions?

Similar Messages

  • Closing cd tray using java application

    sir,
    i want to close the cd tray using java program.i opened it using a vbs file which can be called through Runtime.getRuntime().exec("WScript <filename.vbs> ");
    But i want to know how can close this cd tray using java programming...
    the vbs file cotains the code for opening as
    CreateObject(\"Shell.Application\").NameSpace(17).ParseName(\"g\" & \":\\\").InvokeVerb(\"e&ject\")");
    Now i want to close the cd tray using a vbscript or through any other method which can be implemented in java..plz help me...........

    You can not do it directly, it would have to be via Runtime.exec, or JNI.
    As to how to do it via VBScript, this would not be the best forum to ask on. I'm sure Google will tell you if you ask it nicely.

  • How can I use regular expression to open files of certain types in java?

    Ok this is the problem I am facing:
    I have a command line input of something like "/usr/foo/bar/*.html"
    and there are multiple files in that folder that end with .html.
    How can I use the input to go through/open all the .html files in Java?
    Help would be greatly appreciated thanks!

    Or if you have to do it in java, check out the interfaces java.io.FileFilter and java.io.FileNameFilter
    http://home.tiscali.nl/~bmc88/java/sbook/0128.html
    class HTMLFilter implements FilenameFilter {
        public boolean accept(File dir, String name) {
            return (name.endsWith(".html"));
    }Cheers,
    evnafets

  • How do I open the CD tray using Windows Keyboard

    How do I open the CD tray of my eMac using a Windows Keyboard that does not have a eject button? If I use uControl Program to switch the alt and Window Keys (the option and ⌘ Keys) I can't use the iJect Program.

    shulmice,
    While not a perfect answer since you have to be logged in before you can open the tray, you can put an eject icon in the menu bar by double-clicking on ~/System/ Library/ CoreServices/ Menu Extras/ Eject.menu

  • How to open/read file using Java in Unix?

    Hi Friends,
    Can you please help me out how to open/read file using java in unix os? I have create one text file in "/home/test.txt" in unix environment. How to open the same file & read using java code?
    - Hiren Modi

    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • How to open specific port using java program

    Hello,
    I want to open ,close port using java comm.plz help me how can i do it.is it possible
    by using java program.later i want to use that specific port to accept the server socket connection .plz
    help me.

    i try this java program.*but it get block in accept method*.tht mean i m not able to make connection with port.
    import java.sql.SQLException;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    class MakeConn
         public final static int PORT = 7788;
    public static java.net.Socket clientSocket = null;
    public static java.io.PrintWriter pw = null; // socket output stream
    public static java.io.BufferedReader br = null;
    public static ServerSocket server_socket;
         public static void main(String[] args) throws SQLException
         try {
              server_socket = new ServerSocket(PORT);
    clientSocket = server_socket.accept();
    System.out.println("CLIENT>>>" + clientSocket);
         br = new java.io.BufferedReader(new java.io.InputStreamReader(clientSocket.getInputStream()));
    pw = new java.io.PrintWriter(clientSocket.getOutputStream(), true);
    String message = br.readLine().trim();
    System.out.println("message is"+message);
    pw.close(); // close everything
    br.close();
    clientSocket.close();
         catch (Exception ex) {
    ex.printStackTrace();
    }

  • How to minimize ie to system tray using java

    click ie minimize button and show an icon in system tray area not in task bar
    and then click the icon to restore the ie window.
    help me about this,thank you very much!

    Use JNI.
    I have seen the code posted on this forum before on how to do this, I think by me. Also the example on using JNI ("99% Java" article) does this.
    So STFF.

  • Select the printer tray using the Java Print Service with JDK 1.4.2

    Hello,
    I have got a problem with 1.4 Printing. I would like to specify the printer tray for printing on Windows platform (XP and NT4.0). I am trying to use the attribute javax.print.attribute.standard.MediaTray class (ex. MediaTray.BOTTOM).
    Howerver, I can control the printer tray if I use the PCL driver of the printer. If I user the postscript driver I am not able to control the printer tray. I can reproduce the problem with 3 different printers (HP, Lexmark and Nashuatec).
    I used the getSupportedAttributeValues to check the supported values of the Media
    Media med[] = (Media[])service.getSupportedAttributeValues(Media.class, null, null);
    for (int k=0; k<med.length; k++) {
    System.out.println("Name : " + med[k].getClass() + " - Value : " + med[k].getValue());     
    With the PCL driver I have the following output and I can control the printer tray.
    Name : class javax.print.attribute.standard.MediaTray - Value : 0
    Name : class javax.print.attribute.standard.MediaTray - Value : 2
    Name : class javax.print.attribute.standard.MediaTray - Value : 4
    Name : class sun.print.Win32MediaTray - Value : 0
    Name : class sun.print.Win32MediaTray - Value : 1
    With the postscript driver I have the following output and I cannot control the printer tray
    Name : class sun.print.Win32MediaTray - Value : 5
    Name : class sun.print.Win32MediaTray - Value : 6
    Name : class sun.print.Win32MediaTray - Value : 7
    Name : class sun.print.Win32MediaTray - Value : 8
    Name : class sun.print.Win32MediaTray - Value : 9
    As I must use the postscript printer, can someone help me?
    Thanks.

    Hello,
    Can you tell me how it's possible to selet the tray using the PCL?
    I print on the following way:
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    AttributeSet aset = new HashAttributeSet();
    aset.add(new PrinterName("\\\\107208\\SBE08111", null)); // select printer
    ......Now I tried to add your code and I get the following output:
    0: Name : class javax.print.attribute.standard.MediaSizeName - Value : 40
    1: Name : class javax.print.attribute.standard.MediaSizeName - Value : 41
    2: Name : class javax.print.attribute.standard.MediaSizeName - Value : 45
    3: Name : class javax.print.attribute.standard.MediaSizeName - Value : 42
    4: Name : class javax.print.attribute.standard.MediaSizeName - Value : 4
    5: Name : class javax.print.attribute.standard.MediaSizeName - Value : 5
    6: Name : class javax.print.attribute.standard.MediaSizeName - Value : 27
    7: Name : class javax.print.attribute.standard.MediaSizeName - Value : 46
    8: Name : class javax.print.attribute.standard.MediaSizeName - Value : 59
    9: Name : class javax.print.attribute.standard.MediaSizeName - Value : 60
    10: Name : class javax.print.attribute.standard.MediaSizeName - Value : 55
    11: Name : class javax.print.attribute.standard.MediaSizeName - Value : 38
    12: Name : class javax.print.attribute.standard.MediaSizeName - Value : 16
    13: Name : class javax.print.attribute.standard.MediaSizeName - Value : 57
    14: Name : class javax.print.attribute.standard.MediaTray - Value : 0
    15: Name : class javax.print.attribute.standard.MediaTray - Value : 2
    16: Name : class javax.print.attribute.standard.MediaTray - Value : 1
    17: Name : class javax.print.attribute.standard.MediaTray - Value : 6
    18: Name : class javax.print.attribute.standard.MediaTray - Value : 4
    19: Name : class sun.print.Win32MediaTray - Value : 0
    20: Name : class sun.print.Win32MediaTray - Value : 1
    It's a printer with to trays, so I suppose the last two lines are important, but I'm not possible to effectively select the tray I want to print..

  • Problem with HowTo guide - Use the BI Java SDK in a Web Dynpro Application

    Hello,
    I am following the HowTo guide - Use the BI Java SDK in a Web Dynpro Application
    at <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e49be590-0201-0010-0c83-fc20e5da124f">this link</a>.
    I have configured the connector on the WAS as needed.
    The problem is that when I run the application I receive an Unauthorized error on the connector URL.
    If I open this URL on a browser I receive a pop-up for UID and PWD and when I enter the same UID and PWD I used to configure the connector I am able to login and see the WSDL.
    Any ideas?

    I've never tried using BI in WebDynpro !!!
    But i foond one posting on the connection problem https://forums.sdn.sap.com/click.jspa?searchID=955524&messageID=2133396
    Regards,Anilkumar

  • Adobe Illustrator CS6 won't open in Mac 10.10 without Java SE 6 Runtime. Where do I get it.

    Adobe Illustrator CS6 won't open in Mac 10.10 without Java SE 6 Runtime. Where do I get it.
    I went to Jave and downloaded the latest version of Java 8 Update 31 for Mac, but it still won't open.

    dchasin,
    You may be able to get round the legacy JAVA requirement as follows:
    Create empty folders at “/System/Library/Java/JavaVirtualMachines/1.6.0.jdk” and “/System/Library/Java/Support/Deploy.bundle”, to make Illustrator use Jave SE 8 as it should.
    The solution was presented by Kals in post #7 here:
    https://forums.adobe.com/thread/1637908
    Here are download sites:
    Win:
    http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419 409.html
    Mac:
    http://support.apple.com/kb/DL1572
    Some have found that the page may turn up blank to start with, so it may be necessary to reload the page.
    Others have found that it may depend on browser. Specifically, a switch from Safari has solved it in one case.

  • Simple XML to Text onversion using XSLT and Java?

    Hi all!
    I'm completly new to using XSLT and Java and are trying to convert a XML file into a ordinary Textfile that I am gonna import into another application.
    I started up writing a ordinary XML parser in Java which interpreted the XML file, but realized later on that it was possible to do with a ordinary XSLT.
    So far it is a 2-step process right now, I've tied my XSLT to the XML file and then just open the XML file up in a ordinary browser and then get the result.
    I found an example (http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=3) where u hook up a XML file and a XSL file separately and the process it, and dump it to Stdout. But do I need to hook up a XSL file like this when the XML file is tied to a XSL file internally?

    Just to give you an example to show you how easy it is: http://www.daniweb.com/forums/thread137587.html

  • Open pdf files using AutoVue

    I need to open pdf files using AutoVue in .Net Desktop application(Windows Form ). Is it possible?
    If it is possible please help me to.
    Thanks
    Bimal

    Out of the box no
    Doing it requires a good knowledge of .Net and JAVA (specifically JNI) in order to build a JAVA wrapper for .Net
    I would recommend to google on how you can interact with a java applet inside an IEFRame that is sitting inside a .Net application
    Java.NET : Integration of Java and .NET - CodeProject
    But your are on your own there

  • Open disk tray in os 9

    I've recently sold a second hand eMac to a client who wanted to buy a newer Mac running OS 9 nativly.
    This is an eMac of the more recent kind, the white kind with no button on the disk tray case.
    But yesterday he asked me how that he should open his disc tray. Apparantly his eject button on his keyboard does not work in OS 9 (but it does in OS X - we've tested this). But there is no button on the case (unless you fidget with that white case thingy and press the black open button with a pensel, inside).
    Is there somebody who can give me some advise on where I could find a usefull answer to open the tray from the system (os 9)?
    thx
    Jonathan

    The eject key on an Apple keyboard should work as expected on an nVidia graphics 700 MHz or 800 MHz eMac booted directly into OS 9. Use Control Panels> Extensions Manager to check for disabled CD/DVD and keyboard extensions (it may help to select View as Packages).
    Check Applications (Mac OS 9) folder / Utilities/ Apple Utilities; there's a utility in there (Eject Extras folder, if I remember right) that can be double-clicked to install an Eject icon in the menu bar (similar to the OS X feature) as well as an Eject control strip module.
    Credit goes to Don Archibald for these two links:
    Eject Extras
    EjectMenu

  • Signature Capture for pocket pc using JSP or JAVA

    hello,
    i need to find a way using jsp or java enviornment in which i can capture the signature which the user has signed on my pocket pc .....??
    please let me know what is the ideal way of doing so and what is the best way to transfer it securely to the server ??
    i am using a pocket pc 2000 on hp jornada 568... so the solution should be supported by pocket pc internet explorer
    thanks in advance & regards, :-))
    Prithipal

    You mean like a hand written signiture right?
    That's awesome, that's a really cool idea. And it's not very hard to implement at all. A java applet will be your best bet. Use version 1.1.8 or something for compatibility. All you have to do make a drawing surface for the user to sign, then send it to the server in one of a varity of ways. I would use a single bit bit map, pixels are on or off.
    For the security end you could have your server run SSL. I don't know if the pocket PC supports that though. If it doesn't, the RSA algorithm is open now, the patent expired, and there are several nice java packages available that implement it. So you can just have the applet read a public key from your server, encrypt the data stream with it as it sends it backs. That will be impossible to crack. ( use at least 64 bit keys. )

  • Unable to create a jco destination using remote AS Java system on myjava sy

    Dear SAP Gurus,
                  I had ce 7.1 and nw 2004s based AS java Systems.I want to create a jco destination in my CE 7.1 system using usermapping data of  nw 2004s for jco communication.So i created a AS Java  system of NW2004s in my CE 7.1 SLD .when i try to create a jco destination using the AS JAVA as Nw2004s system it is not creating .Please help me to solve this issue.
    regards,
    vanamaSanthosh.

    Hi vanamaSanthosh
    try this
    1. In your CE1 System where u define your JCO destination, Go to C:\WINDOWS\system32\drivers\etc
    open hosts file and define the  identity of AS System like <IP address> <name of the system>
    for example 159.858.2.45  abcd
    restart the server and then check.
    Best Regards
    Satish Kumar

Maybe you are looking for

  • Save As default location problem

    Hi, I have CS3 installed on a brand new Mac Pro. I have a few sites set up in Dreamweaver. When I open a file from the file panel, and do a "Save As" to save this file somewhere else or change the name, the dialog keeps starting out at "Documents" in

  • I have forgotten my pin for my iphone how do i reset it?

    Hello Apple Somehow I have managed to forget passcode .Is there a way of unlocking it again ? <edited by host>

  • What's the beste wireless router for ADSL?

    Hello everyone, Since I'm new to the Macworld, I'd like to know what's the best wireless modem to the Macbook. I've been looking forward to the Netgear one, but other options like D-Link that are lesse expensive. So, what's the best option for connec

  • [PS] Multiple array´s split and merge

    Is it possible to: when you have 3 array's split the value's after the comma and then from each array merge every 1st value with 1st, 2 with 2 and so on. I know you can use split to split up an array, but i have no clue how to merge it like i want. e

  • Apo dp support

    hi sir good morning actually am going to assign in support project by the company within couple of days. Acutually i don't have any support experience. As per DP MODULE What will we do in the support project.  What kind of quiries we will get. i thou