SHARE
TWEET

Untitled

a guest Jun 17th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package foroverflow;
  2. public class ForOverflow {
  3.     public static void main(String[] args) throws Exception {
  4.         System.out.print("Ingrese la cantidad de procesos a detener: ");
  5.         ForOverflow1 obj = new ForOverflow1();
  6.         obj.Procesos_aaa();
  7.         ForOverflow2.killProcess();
  8.     }
  9. }
  10.  
  11. package foroverflow;
  12. import java.util.Scanner;
  13. public class ForOverflow1 {
  14.     Scanner in = new Scanner(System.in);
  15.     String Procesos[] = new String [in.nextInt()];  
  16.     public void Procesos_aaa() {
  17.         in.nextLine();
  18.         for(int con = 0; con < Procesos.length; con++) {
  19.             System.out.print("Ingresa el nombre del " + ++con + " proceso, (x ej: chrome.exe): ");
  20.             Procesos[--con] = in.nextLine();
  21.          }
  22.     }
  23.     public String[] getProcesos() {
  24.         return Procesos;
  25.     }
  26. }
  27.  
  28. package foroverflow;
  29. import java.io.BufferedReader;
  30. import java.io.InputStreamReader;
  31. public class ForOverflow2 {
  32.     private static final String TASKLIST = "tasklist";
  33.     private static final String KILL = "taskkill /F /IM ";
  34.  
  35.     public static boolean isProcessRunning(String serviceName) throws Exception {
  36.         Process p = Runtime.getRuntime().exec(TASKLIST);
  37.         BufferedReader reader = new BufferedReader(new
  38.         InputStreamReader(p.getInputStream()));
  39.         String line;
  40.         while ((line = reader.readLine()) != null) {
  41.             System.out.println(line);
  42.                 if (line.contains(serviceName)) {
  43.                     return true;
  44.                 }
  45.         }
  46.         return false;
  47.     }
  48.  
  49.     public static void killProcess() throws Exception {
  50.         ForOverflow1 obj = new ForOverflow1();
  51.         for (String aaa : obj.getProcesos()) {
  52.             Runtime.getRuntime().exec(KILL + aaa);
  53.         }
  54.     }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top