Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. How to close MS Word(or any program are in progress) using java

How to close MS Word(or any program are in progress) using java

Scheduled Pinned Locked Moved Java
javatutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharkbc
    wrote on last edited by
    #1

    Dear all ! I installed MS Word at C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE I point to WINWORD.EXE and open it. After that, how can close WINWORD.EXE using my java app. Thanks

    T C A 3 Replies Last reply
    0
    • S sharkbc

      Dear all ! I installed MS Word at C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE I point to WINWORD.EXE and open it. After that, how can close WINWORD.EXE using my java app. Thanks

      T Offline
      T Offline
      TorstenH
      wrote on last edited by
      #2

      is Google offline :confused: The Commandline in Windows[^] greets Torsten

      I never finish anyth...

      1 Reply Last reply
      0
      • S sharkbc

        Dear all ! I installed MS Word at C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE I point to WINWORD.EXE and open it. After that, how can close WINWORD.EXE using my java app. Thanks

        C Offline
        C Offline
        crystaljava
        wrote on last edited by
        #3

        JNI may be useful,because the windows sdk can do that~

        1 Reply Last reply
        0
        • S sharkbc

          Dear all ! I installed MS Word at C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE I point to WINWORD.EXE and open it. After that, how can close WINWORD.EXE using my java app. Thanks

          A Offline
          A Offline
          Arun Reginald Zaheeruddin
          wrote on last edited by
          #4

          As far as I know, you are only allowed to kill a process directly from within Java if it was started from the currently running Java code. However, if a certain process was not started from within your Java code, you would need to use a native third-party tool to do the job for you. Thankfully, if you have Windows OS versions greater than Server 2003 or Vista, you can use the TASKKILL.EXE command-line application present in the ~\WINDIR\system32 folder to kill a certain task. Or perhaps, you can use the following code to do this explicitly from within your Java code:

          Runtime runtime = Runtime.getRuntime();
          String[] killArgs = {"TASKKILL", "/IM", "WINWORD.EXE"};
          try
          {
          Process processToKill = runtime.exec(killArgs);
          processToKill.waitFor();
          System.out.println(
          new StringBuffer()
          .append("Process exit code: ")
          .append(processToKill.exitValue())
          .toString());
          System.exit(0);
          }
          catch(java.io.IOException ex)
          {
          ex.printStackTrace();
          System.exit(1);
          }
          catch(InterruptedException ex)
          {
          ex.printStackTrace();
          System.exit(1);
          }

          Tell me if this works for you. I certainly hope this is what you were looking for.


          The beginning of knowledge is the fear of God

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups