private static void restrict () { try { String strOutput="", strError=""; Process p = Runtime.getRuntime().exec(new String[]{"cmd", "/c", "tasklist /svc"}); BufferedReader stdInput= new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); while (strOutput != null) { if(strOutput.toLowerCase().contains("winword.exe")) { System.out.println("found specified file"); Runtime.getRuntime().exec("taskkill /im winword.exe"); System.out.println("killed."); } if (strOutput.length() < 1) { } else { System.out.println(strOutput); } strOutput = stdInput.readLine(); } strError = stdError.readLine(); if (strError != null) { System.out.println("An error occured"); while (strError != null) { System.out.println(strError); strError = stdError.readLine(); } } } catch (IOException ex) { System.out.println(ex.getMessage()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)