How do I close an open file inside a MS Office application via Java? -


for example, i've test.pptx open in microsoft powerpoint 2013 on windows 10. want close without closing microsoft powerpoint itself. how can using java 1.8?

because it's external program, need kill pc running power point task.
can achieve using below java code:

import java.io.bufferedreader; import java.io.inputstreamreader;  public class closepowerpoint {      private static final string tasklist = "tasklist";     private static final string kill = "taskkill /im ";      public static void main(string args[]) throws exception {             system.out.print(isprocessrunging("powerpnt.exe"));          if (isprocessrunging(processname)) {              killprocess(processname);         }     }      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);      }    } 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -