Cosing an Application in Java

Posted on 2004-11-11
Last Modified: 2010-05-02
I know that the code to open an application is this::::::Runtime.getRntime().exec(C:Word.exe);
but how can i close an application in Java ???
Question by:casper_the_ghost
    LVL 48

    Expert Comment


    should be:


    Author Comment

    Sowhen i close a word pplicationi just use System.exit()??? ow would my program know which aplication to close if have multiple program that's open??? Do i put the path of he appliation inside the exit method??
    LVL 48

    Accepted Solution

    can i close an application in Java  i thought you meant your own app

    you have to use the windows api to do this.  To use the windows api, you have to call a dll function using JNI.

    If you want to do this, here is what your exported native function would look like:

    #include <windows.h>
    #include <jni.h>
    #include "JavaClass.h"

    Java_JavaClass_closeNotepad(JNIEnv *env, jobject obj)
        HWND wndHandle = FindWindow("Notepad",NULL);

    More info on JNI here

    Author Comment

    this seemed like it's written in Visual Basic or you have a sample code written in Java??
    LVL 27

    Expert Comment

    javascript != java;

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now