Results 1 to 9 of 9
  1. #1
    j3i8x is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default close another program???

    Hi guys/

    I'm new in java
    Can you tell me how to close another program (web browser, note pad, ... ) in java ?

    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: close another program???

    One way would be to use the Robot class to move the cursor to the program's close button and press it.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: close another program???

    Why do you need to do this?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    j3i8x is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: close another program???

    thanks for your answers,

    how can i find the button close ?

    this is my project. i want to use java program to control (open, close) another program.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: close another program???

    Quote Originally Posted by j3i8x View Post
    how can i find the button close ?

    this is my project. i want to use java program to control (open, close) another program.
    If Java started the other program, then you could kill the Process that Java created. If Java did not start the other program, then I'd change projects, because Java is not the right tool for this job, and in fact is a terrible tool for this job. Better to use C/C++, or some batch language such as AutoIt (if Windows).

  6. #6
    j3i8x is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: close another program???

    Quote Originally Posted by Fubarable View Post
    If Java started the other program, then you could kill the Process that Java created.
    please tell me how to do that.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: close another program???

    First please tell us exactly what you're trying to do. Please include the necessary details as they are important if we are to understand what is going on, and can have a chance of helping you.

  8. #8
    j3i8x is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: close another program???

    finally found what I want to do.

    thanks you guys

    import java.io.BufferedReader;
    import java.io.InputStreamReader;

    public class Kill_NotePad {

    private static final String TASKLIST = "tasklist";
    private static final String KILL = "taskkill /IM ";

    public static boolean isProcessRunging(String serviceName) throws Exception {

    Process p = Runtime.getRuntime().exec(TASKLIST);
    BufferedReader reader = new BufferedReader(new InputStreamReader(
    p.getInputStream()));
    String line;

    while ((line = reader.readLine()) != null) {

    System.out.println(line);
    if (line.contains(serviceName)) {
    return true;
    }
    }
    return false;
    }

    public static void killProcess(String serviceName) throws Exception {

    Runtime.getRuntime().exec(KILL + serviceName);

    }


    public static void main(String args[]) throws Exception {
    String processName = "notepad.exe";

    System.out.print(isProcessRunging(processName));

    if (isProcessRunging(processName)) {

    killProcess(processName);
    }
    }
    }

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: close another program???

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 10
    Last Post: 09-17-2011, 11:59 AM
  2. Replies: 13
    Last Post: 04-09-2010, 11:15 AM
  3. close to zero
    By nokicky in forum New To Java
    Replies: 6
    Last Post: 10-26-2009, 04:30 PM
  4. How to close a JFrame
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:33 PM
  5. Close a program in java
    By romina in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 07:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •