Guest User

Untitled

a guest
Sep 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. if(isProcessRunning("Taskmgr.exe")){
  2. // TODO code application logic here
  3. killProcess("Taskmgr.exe");
  4. }
  5.  
  6. public static boolean isProcessRunning(String servicename) throws Exception {
  7.  
  8. Process p = Runtime.getRuntime().exec(TASKLIST);
  9. BufferedReader reader = new BufferedReader(new InputStreamReader(
  10. p.getInputStream()));
  11. String line;
  12. while ((line = reader.readLine()) != null) {
  13. System.out.println(line);
  14. if (line.contains(servicename)) {
  15. System.err.println(line);
  16. return true;
  17. }
  18. }
  19.  
  20. return false;
  21.  
  22. }
  23.  
  24. public static void killProcess(String serviceName) throws Exception {
  25.  
  26. Runtime.getRuntime().exec(KILL + serviceName);
  27.  
  28. }
Add Comment
Please, Sign In to add comment