Controling windows volume from java

Hi! Firstable, sorry for my English.
My question is very simple
How can I control windows' volume from java?
I've searched everywhere, but I found nothing.
JMF did not help me, I just could control a line, but I want to control the master volume of my pc.
Thanks in advance...

If you can identify a Windows command that does what you want, then you can execute it using Java's ProcessBuilder class nethods. If not, you can use Java Native Interface (JNI) or one of its variations to create an interface from Java to C/C++ code in Windows.

Similar Messages

  • Start and Stop a Windows Service From Java

    Is there any way to start and stop a Windows service from Java? The only post I found on it (http://forum.java.sun.com/thread.jspa?threadID=647509) had a link to one of the many aps that allow Java programs to be services, which is not what I am interested in doing.
    I am attempting to get data from performance counters from the Windows Performance Monitor into a Java ap without using JNI. I can get the data from C++ or a .net language pretty easily and was going to create a service that would listen for socket requests and feed back the data. However, I'd like to start and stop that service when my java code starts and stops. Is this possible? Would it make more sense to just use a .exe and Runtime.exec()?

    If it's only to start or stop a service then you could use the net command without any need for JNI.import java.io.*;
    public class MsWinSvc {
        static final String CMD_START = "cmd /c net start \"";
        static final String CMD_STOP = "cmd /c net stop \"";
        public static int startService(String serviceName) throws Exception {
            return execCmd(CMD_START + serviceName + "\"");
        public static int stopService(String serviceName) throws Exception {
            return execCmd(CMD_STOP + serviceName + "\"");
        static int execCmd(String cmdLine) throws Exception {
            Process process = Runtime.getRuntime().exec(cmdLine);
            StreamPumper outPumper = new StreamPumper(process.getInputStream(), System.out);
            StreamPumper errPumper = new StreamPumper(process.getErrorStream(), System.err);
            outPumper.start();
            errPumper.start();
            process.waitFor();
            outPumper.join();
            errPumper.join();
            return process.exitValue();
        static class StreamPumper extends Thread {       
            private InputStream is;
            private PrintStream os;
            public StreamPumper(InputStream is, PrintStream os) {
                this.is = is;
                this.os = os;
            public void run() {
                try {
                    BufferedReader br = new BufferedReader(new InputStreamReader(is));
                    String line;
                    while ((line = br.readLine()) != null)
                        os.println(line);
                catch (Exception e) {
                    e.printStackTrace();
    }Regards

  • I can't control the volume from my iphone 4 headset. What can I do???

    I can't control the volume from my iphone 4 headset. What can I do???

    Go to Settings > Sounds. There is this option call Change With Buttons. Is it On or Off?

  • Configuring Windows Scheduler from Java Class

    Hi Frnds ,
    Is it possible to configure or create a task in Windows Scheduler from a Java program .
    If so ,please let me know how we can do so .
    Thanks ,
    Rajesh Reddy

    Without claimimng any hands-on experience with this, google for "windows scheduler command line".
    You will see lots of information from Microsoft about command line utilities that manage the scheduler.
    If those utilities are able to do what you need, calling them from Java is just a matter of using the
    Runtime or, better, ProcessBuilder classes (Runtime.exec() or ProcessBuilder.start()).

  • Querying windows service from Java

    Hi All,
    i have a java web application running on jboss that does data collection by querying different windows processes like MSSQLSERVER, IIS availability etc.
    The problem i am facing is that my application is returning a negative result for the above services but when i run the query from command prompt i get a positive result. I dont understand why this happens.
    would really appreciate a response.

    Is query this from java Runtime.exec and from command prompt different? My code creates a string of sc \\<server> query W3SVC and calls this like:               String cmd = "sc "+ " \\\\ " + serverIPOrHostName + "query"+ service;
                   p = r.exec(cmd);
                   inp = p.getInputStream();
                byte[] dataInput = new byte[320];
                inp.read(dataInput);
                String inputData = new String(dataInput);
                //Logger added to read the service response.
                logger.info(inputData);
                //Checks for specified sequence of characters in the string and
                //returns boolean.
                if (inputData.contains(SERVICE_RUNNING)) {
                     result = 1;
                } else {
                     result = 0;
                }My reasoning is that if i cant do it in java because of some security policy then i should not be able to do it in command prompt too? But that is not the case. I can do it over command prompt but not from java code!
    If this is a windows related issue, how should i proceed to debug it? how can i provide access to my java code to do this?
    I happened to check out one site http://www.kbalertz.com/kb_Q323790.aspx where it says that "The File and Printer Sharing for Microsoft Networks component must be turned on for many remote-management functions to work. "
    But this looks like a very trivial (although i dont know much about windows security policies).
    thanks,
    Dilip
    PS: Thanks for looking into the mail and responding.

  • Controlling external programs from Java

    Hi,
    I try to invoke an external command-line program in Windows 2000 fron Java. I do this by
    Process proc = Runtime.getRuntime().exec(cmd);
    cmd is a String representing a command. For instance I try to control the gnupg program by
    "cmd /c C:\\gnupg\\gpg --list-keys"
    This works fine. But when I want to make a more advanced control, when gnupg waits for more than one input, and that input can't be put on the same line I get problems.
    When running gpg --edit-key SomeKey on the command line I have to enter
    trust - return - 5 - return - yes - return - quit
    How do I do this?

    this is how to do it! gotta listen to the output to prevent deadlock. you can pass in parameters o the initial call as well (a string array, where string[0] = command, string[...] = input argument) or write it to the output stream of the process.
    hope this helps
    public void run_command(String starting_command, String[] further_commands)
    Process proc = Runtime.getRuntime().exec(starting_command);
    Listener.make(proc.getInputStream());//these listen to the streams
    Listener.make(proc.getErrorStream());//which prevents deadlock
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(proc.getOutputStream()));
    for(int i = 0;i < further_commands.length;i++)
    writer.println(further_commands);//you could put the extra stuff as the first string in this array
    import java.io.*;
    public class Listener extends Runnable
    BufferedReader reader;
    public static void make(InputStream in)
    Listener l = new Listener(in);
    Thread thread = new Thread(l);
    thread.start();
    public Listener(InputStream in)
    reader = new BufferedReader(new InputStreamReader(in));
    public void run()
    String string;
    while(true)
    string = reader.readLine();
    try
    Thread.sleep(1000);
    catch(Exception e)

  • Controlling a browser from java

    hello experts,
    i want to open an web dynpro URL in a browser and navigate through the URL , like putting values in the input box and click the buttons from java code .
    Actually it is exactly like an automated test tool in java to navigate and render the given web dynpro URL with the test data given.
    its very please help.
    Regards,
    Karthik

    Hello Karthik,
    I'm using Selenium to do something similar. You can find more information at http://seleniumhq.org/
    The documentation can be found at http://seleniumhq.org/documentation/ and you can find a tutorial implementation for Java at http://seleniumhq.org/documentation/tutorials/
    You can use a new Java Project to start using Selenium, just in case you feel confused.
    I've been using Selenium for some time now, you will learn some tricks during the way. And you'd probably take a look on waitForCondition function, since you'd need some calls in order to wait for webdynpro ajax requests to populate tables (before doing your assertions).
    Hope it helps.
    Regards,
    Daniel

  • Monitoring windows services from JavaI Know how to

    I know how to start and stop services in java, but how can I see if a process is already stared or is starting?
    Thx

    You'll need to make a call to a suitable Windows program using Runtime or ProcessBuilder methods, or use JNI (Java Native Interface.) From Wikipedia:
    (JNI) is a programming framework that allows Java code running in the Java virtual machine (JVM)
    to call and be called[1] by native applications (programs specific to a hardware and operating system
    platform) and libraries written in other languages, such as C, C++ and assembly.

  • Calling windows programs from Java

    Hello,
    I need to find how to call and pass parameters to windows programs. Specifically I need to call MS Sql server, there is call that I can do from command promt but I would like to give it some GUI interface and ease of use so I could pass some parameters to the program and execute it.
    Thanks.

    Hi thanks for all replies !
    Ok let me explain more about my problem.
    I have a SQL server which runs on MS machine and there is thousands of stored procs that my be recreated once in a while from a directorys. So we have scripts which we have to manually update every time new stored proc is written and run against the server to update all of them at one batch.
    Now I often have to browse to this directory from linux machine and I basically already written the Java program that gets all the files in the directory and passes them via JDBC to the server.
    Thats where the problem starts, when you calling and passing sp to sql without any header seting the jdbc is fine but when you pass sp with such settings for instanse as "SET QUOTED_IDENTIFIER and SET ANSI_NULLS OFF" in the header of stored proc then SQL server complains and fires exceptions on me.
    So this is my problem.

  • Handling an external (Windows) process from Java.

    There is an example program in the 3rd edition of "The Java Language" by Gosling, et. al. The example is a simplified shell to handle an external executable. This is the code:
    public static Process userProg(String cmd) {
        Process child = Runtime.getRuntime().exec(cmd);
        plugTogether(System.in, child.getOutputStream());
        plugTogether(System.out, child.getInputStream());
        plugTogether(System.err, child.getErrorStream());
    }I have tried various means to make this skeleton work but to no avail. Is anybody aware of an example that would show how to not only startup an external executable but manage it with I/O? I have plenty of examples that startup something like:
    String[] cmdLine = {"ls", "-l" "dir"};
    Runtime.getRuntime().exec(cmdLine);
    ...But none of them control an external application like ftp that require an interactive session. If anyone can point me towards a book, website url, example here at Sun, I'd appreciate it but it needs to be an example that controls an external executable through input and output. Thanks.
    -John

    OK.
    This is not exactly an "example"; it is actual code from a production program. Names have been changed to protect proprietary info, so it is not clear that this will even compile. (Also: I would write this differently today, so please don't show this to anyone:-)
    Key limitations as an example:
    o The server is proprietary, so you can't see it.
    o The scripting language is proprietary, so you can't see it.
    This is a fragment of the interface between a large java application and a session-based server. The server was fed scripts - lines of interpreted code; the server executed the script. Key points:
    o If the script terminated with an "execute"command, then the server would hang around waiting for more scripts.
    o If the script terminated with an end, then the server process would exit.
    o What the server "said" in response was controlled by print statements in the script it was fed.
    Note the goofy print statements that allow my client to detect when the server completed a given transmission.
    import java.util.Enumeration;
    import java.util.Vector;
    import java.io.*;
    import Logger;
    * Provides data from proprietary server.
    public class ServerAccess {
          * Class to write script to server.
         private class Writer implements Runnable {
              Vector script;
              PrintStream p;
               * Constructor - establish a print stream to server.
              Writer(OutputStream s) {
                   p = new PrintStream(s);
               * Save the script to be written and start the writer.
              public void init( Vector script) {
                   this.script = script;
                   new Thread(this).start();
               * Thread to write script lines.
              public void run() {
                   for (Enumeration e = script.elements(); e.hasMoreElements(); ) {
                        p.println((String)e.nextElement());
                   // Make sure everything gets written out.
                   p.flush();
              public void finalize() {
                   // Shut down the print stream.
                   p.close();
         public boolean init() {
              // Access runtime so process can be created.
              Runtime r = Runtime.getRuntime();
              // Execute server.
              try {
                   p = r.exec("server.exe");
                   return true;
              catch(Exception e) {
                   Logger.logAlways("ServerAccess: Couldn't execute server. " + e.toString());
                   return false;
          * Terminate access to server.
         public void terminate() {
              Vector script = new Vector();
              script.add("end");
              // Write script to server process.
              Writer w = new Writer(p.getOutputStream());
              w.init(script);
              BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
              try {
                   String line;
                   while ((line = b.readLine()) != null) {
              catch (Exception e) {
                   Logger.logAlways("ServerAccess: Couldn't terminate server. " + e.toString());
              return;
          * Test method.
         public void runTest() {
              // Create test script.
              Vector script = new Vector();
              script.add(....);
              script.add("print END_OF_OUTPUT %RET");
              script.add("execute");
              // Write script to server process.
              Writer w = new Writer(p.getOutputStream());
              w.init(script);
              BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
              try {
                   String line;
                   while (true) {
                   line = b.readLine();
                   if (line.equals("END_OF_OUTPUT"))
                        break;
                        System.out.println(line);
              catch (Exception e) {
                   System.err.println(e.toString());
         * Test.
        public static void main(String[] args) {
            ServerAccess a = new ServerAccess();
              try {
                   a.init();
              catch(Exception e) {
                System.err.println(e.toString());
                return;
            a.runTest();
            a.terminate();
         // Object attributes.
        private Process p = null;
         String END_OF_PACKAGE = "END_OF_CONTENT";
         String END_OF_OUTPUT = "END_OF_OUTPUT";

  • Run windows services from java application

    can java application run a windows server
    i have a web server that runing using tomcat and mysql
    can i make a icon in the systray
    that give me the option to (using a menu)
    run the server ,wicth means : tomcat and mysql are runing
    stop the server
    get tomcat stacktrace in a window
    i was thinking about runing tomcat and mysql as services
    and write the systray application using java,
    the systray application should acces window services ,
    and run/stop requierd services.
    what happend on a machine thar runs linux?
    thanks
    shay

    Ok .so it's will be a diffrent way under linux..
    for systray i will use http://systray.sourceforge.net/
    and for services i'll use the
    "net start <Service>" and "net stop service"
    i need to keep track on the service status
    so my Systray status will be updated
    what is the command for getting the status of the proccess
    thanks shay

  • Can Mac OS X control sound volume from the bash shell?

    hi!
    first time ever that i ask in a forum something....
    I wanted to know if there was something that looked like the amixer function for linux. I want to control the overall output volume of my audio card, without using AppleScript. I tried to look for something on the net, but all i was getting was just useful (and a lot) for Applescript. I was wondering if there is something that could be done with the terminal commands.
    Thanks

    Try using a Terminal command such as:
    osascript -e 'set volume 1'
    (28042)

  • Spawning Windows commands from Java not working ...?

    Using either ProcessBuilder nor Runtime.getRuntime() to invoke the WinXP xcopy command is failing.
    The xcopy command starts then unexpectedly stops never returning to the process.waitfor
    The command working from the command line just fine.
    Here is a the interesting bit of the code:
    final String cmd = "xcopy /E /C /I /R /Y " + cpy_from + " " + install_folder;
    //final String cmd = "SCOT_Post_Install.bat";
    //Folder creation
    try
      scot_installer.log("xcopy: " + "Copying student stations");
      String station_num = "" + i;
      String[] commands = {"cmd", "/c", cmd, station_num};
      scot_installer.log("xcopy: Attempting to invoke: " + cmd);
      Process p = Runtime.getRuntime().exec(commands);
      p.waitFor();
      log ("Exit value of process: " + p.exitValue());               
      //p.destroy();
      //p = null;
       catch (Exception ex)
             scot_installer.log("xcopy: " + ex.toString());
       All I can guess is that there is a lot to copy and the there is a memory issue with the command.
    The "xcopy" command starts out looking "normal" in the task manager ...
    then xcopy command looks like a zombie process in the task manager.
    The memory is stable and it uses no significant CPU time
    Also, I noticed when I killed the running process through Netbeans -- the xcopy command became "freed up" to finish.
    But, of course, this does me no good because there are a lot more copies I need to make.

    vulpes123 wrote:
    Using either ProcessBuilder nor Runtime.getRuntime() to invoke the WinXP xcopy command is failing.
    The xcopy command starts then unexpectedly stops never returning to the process.waitfor
    The command working from the command line just fine.
    I haven't used xcopy since 1994, but it's probably writing data to stdout or stderr and you must read the data from those streams. The process will block if the buffers for stdout and stderr gets full.
    Kaj

  • Execute windows ping from java....

    Why don't work �?�?�?
    import java.io.*;
    class runtime{
    public static void main(String Arg[]) throws IOException
    Runtime r=Runtime.getRuntime();
    Process p= null;
    try{
    p=r.exec("ping.bat") ;
    System.out.println("Finalizo la ejecuci�n de ping");
    }catch(Exception e){ System.out.println("Error al ejecutar la instrucci�n");}
    the output is always "Finalizo la ejecucion de ping" but i don't see the output of the ping.Help me.Thxx.

    here's an example:
    public int someCall() throws Exception
    Process p;
    int intResult;
    String strExec = new String("ping java.sun.com");
    p=Runtime.getRuntime().exec(strExec); // start the process
    // now set something up that scans for output (independently)
    MGStreamGobbler mgSGErrors = new MGStreamGobbler(p.getErrorStream(),"error ");
    MGStreamGobbler mgSGOutput = new MGStreamGobbler(p.getInputStream(),"output ");
    // start the somethings
    mgSGErrors.start();
    mgSGOutput.start();
    // now wait for the actual process to end, wait for it's result
    intResult=p.waitFor();
    return(intResult);
    the StreamGobbler class - it's simple, it just waits for input and writes it,
    with a prefix, to System.out - feel free to redirect elsewhere:
    class MGStreamGobbler extends Thread
    InputStream isSource;
    String strType;
    OutputStream osGoal;
    MGStreamGobbler(InputStream isParSource, String strParType)
    isSource=isParSource;
    strType=strParType;
    public void run()
    try
    InputStreamReader isrSource = new InputStreamReader(isSource);
    BufferedReader brSource = new BufferedReader(isrSource);
    String strLine=null;
    while ( (strLine = brSource.readLine()) != null)
    System.out.println(strType + ">" + strLine);
    } catch (Exception ex)
    System.out.println(" "+ex.toString());
    if you ignore the error stream, you don't need a thread but only a while after the exec call

  • How to restart windows (any) from java program

    What is the system program that I have to call in order to restart windows...
    Runtime.getRuntime().exec(???);

    I hope your app is first asking the user for
    permission to do that first. Otherwise be prepared to
    be smacked upside the head with a smelly sock when
    you reboot when the user really really really didn't
    want you to.I'm actually counting on natural selection to do its work in this case. That's why I was willing to help.

Maybe you are looking for

  • Accrual/Reversing Document and Parked Invoices

    Hi, Our company does not use PO, and probably never will for practical reasons. However, what we do do is park invoices. Invoices come in to our head office, and before the invoices are sent out for signing/authorisation we park the invoices. Come mo

  • IPad model ml769ll1a v7.0.4 anyway to connect to camera sd card?

    This iPad does not have the newer smaller connector that my new iPhone has so the accessory connectors listed for digital camera connection or sd card reader would not fit this. Am I just out of luck on this model?.

  • Part appearing to be ordered in me21n

    Hi Gurus, can anybody plz help me with this? Part number xxxx keeps showing up for me to order thru MRP but there is no opens sales order that I can find.  This is a third party shipment. Can you please explain to me why this keeps appearing on my Cr

  • How to (grep) similar words ending or not in s?

    The idea is to recognize identical words like: car /cars house/houses, etc. Could not solve with look-behinds, etc.

  • Avoid Hard Parsing for executing dynamic SQL using DUAL table Oracle

    I want to know if dynamic sql statements involving DUAL table can be modified to remove HARD PARSING. We have several SQL statements are stored in configuration table, here is sample example -- query 1 before replacing index values as stored in confi