|
@@ -14,6 +14,50 @@ public class ProcessUtil {
|
|
|
private static BufferedReader out;
|
|
|
private static BufferedReader err;
|
|
|
public static Logger logger = Logger.getLogger(ProcessUtil.class);
|
|
|
+
|
|
|
+ public static List<String> getExeprocessListfromProcessStr(String processStr) {
|
|
|
+//以下为进程字符串示例
|
|
|
+// String processStr =
|
|
|
+// "ӳ������ PID �Ự�� �Ự# �ڴ�ʹ�� \n" +
|
|
|
+// "========================= ======== ================ =========== ============\n" +
|
|
|
+// "System Idle Process 0 Services 0 8 K\n" +
|
|
|
+// "System 4 Services 0 20 K\n" +
|
|
|
+// "Registry 144 Services 0 39,108 K\n" +
|
|
|
+// "smss.exe 568 Services 0 352 K\n" +
|
|
|
+// "csrss.exe 740 Services 0 2,148 K\n" +
|
|
|
+// "wininit.exe 948 Services 0 2,420 K\n" +
|
|
|
+// "services.exe 1020 Services 0 6,776 K\n" +
|
|
|
+// "lsass.exe 124 Services 0 12,660 K\n" +
|
|
|
+// "svchost.exe 708 Services 0 1,140 K\n" +
|
|
|
+// "fontdrvhost.exe 732 Services 0 532 K\n" +
|
|
|
+// "svchost.exe 688 Services 0 29,176 K\n" +
|
|
|
+// "WUDFHost.exe 1028 Services 0 10,032 K\n" +
|
|
|
+// "svchost.exe 1096 Services 0 15,176 K\n" +
|
|
|
+// "svchost.exe 1144 Services 0 5,140 K\n" +
|
|
|
+// "WUDFHost.exe 1328 Services 0 2,168 K\n" +
|
|
|
+// "svchost.exe 1500 Services 0 2,432 K\n" +
|
|
|
+// "svchost.exe 1512 Services 0 6,704 K\n" +
|
|
|
+// "svchost.exe 1576 Services 0 8,208 K\n" +
|
|
|
+// "svchost.exe 1628 Services 0 4,608 K\n" +
|
|
|
+// "svchost.exe 1636 Services 0 5,604 K\n" +
|
|
|
+// "svchost.exe 1648 Services 0 4,764 K\n" +
|
|
|
+// "svchost.exe 1776 Services 0 3,488 K\n" +
|
|
|
+// "svchost.exe 1828 Services 0 1,536 K\n" +
|
|
|
+// "svchost.exe 1840 Services 0 4,204 K\n" +
|
|
|
+// "svchost.exe 1848 Services";
|
|
|
+ List<String> exeprocessList = new ArrayList<>();
|
|
|
+ String[] list = processStr.toLowerCase().split("k\n");
|
|
|
+ //从第三行开始才是系统的.exe进程
|
|
|
+ for (int i = 3; i < list.length; i++) {
|
|
|
+ // 必须写死,截取长度,因为是固定的
|
|
|
+ exeprocessList.add(list[i].substring(0, 25).trim()); // 进程名
|
|
|
+// System.out.println(process);
|
|
|
+ }
|
|
|
+ return exeprocessList;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static void testProcess() {
|
|
|
// 创建系统进程
|
|
|
try {
|
|
@@ -27,7 +71,7 @@ public class ProcessUtil {
|
|
|
// System.out.println(err.readLine());
|
|
|
// 创建集合 存放 进程+pid
|
|
|
List<String> list = new ArrayList<>();
|
|
|
- while (out.readLine()!= null) {
|
|
|
+ while (out.readLine() != null) {
|
|
|
System.out.println(out.readLine());
|
|
|
list.add(out.readLine());
|
|
|
}
|
|
@@ -71,7 +115,48 @@ public class ProcessUtil {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
+// String processStr =
|
|
|
+// "ӳ������ PID �Ự�� �Ự# �ڴ�ʹ�� \n" +
|
|
|
+// "========================= ======== ================ =========== ============\n" +
|
|
|
+// "System Idle Process 0 Services 0 8 K\n" +
|
|
|
+// "System 4 Services 0 20 K\n" +
|
|
|
+// "Registry 144 Services 0 39,108 K\n" +
|
|
|
+// "smss.exe 568 Services 0 352 K\n" +
|
|
|
+// "csrss.exe 740 Services 0 2,148 K\n" +
|
|
|
+// "wininit.exe 948 Services 0 2,420 K\n" +
|
|
|
+// "services.exe 1020 Services 0 6,776 K\n" +
|
|
|
+// "lsass.exe 124 Services 0 12,660 K\n" +
|
|
|
+// "svchost.exe 708 Services 0 1,140 K\n" +
|
|
|
+// "fontdrvhost.exe 732 Services 0 532 K\n" +
|
|
|
+// "svchost.exe 688 Services 0 29,176 K\n" +
|
|
|
+// "WUDFHost.exe 1028 Services 0 10,032 K\n" +
|
|
|
+// "svchost.exe 1096 Services 0 15,176 K\n" +
|
|
|
+// "svchost.exe 1144 Services 0 5,140 K\n" +
|
|
|
+// "WUDFHost.exe 1328 Services 0 2,168 K\n" +
|
|
|
+// "svchost.exe 1500 Services 0 2,432 K\n" +
|
|
|
+// "svchost.exe 1512 Services 0 6,704 K\n" +
|
|
|
+// "svchost.exe 1576 Services 0 8,208 K\n" +
|
|
|
+// "svchost.exe 1628 Services 0 4,608 K\n" +
|
|
|
+// "svchost.exe 1636 Services 0 5,604 K\n" +
|
|
|
+// "svchost.exe 1648 Services 0 4,764 K\n" +
|
|
|
+// "svchost.exe 1776 Services 0 3,488 K\n" +
|
|
|
+// "svchost.exe 1828 Services 0 1,536 K\n" +
|
|
|
+// "svchost.exe 1840 Services 0 4,204 K\n" +
|
|
|
+// "svchost.exe 1848 Services";
|
|
|
+// String[] list = processStr.split("K\n");
|
|
|
+// for (int i = 3; i < list.length; i++) {
|
|
|
+// // 必须写死,截取长度,因为是固定的
|
|
|
+// String process = list[i].substring(0, 25).trim(); // 进程名
|
|
|
+// System.out.println(process);
|
|
|
+// String pid = list[i].substring(25, 35).trim(); // 进程号
|
|
|
+ // 匹配指定的进程名,若匹配到,则立即杀死
|
|
|
+// if (process.startsWith("Thunder")) {
|
|
|
+// System.out.println("关闭迅雷");
|
|
|
+// Runtime.getRuntime().exec("taskkill /F /PID " + pid);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
testProcess();
|
|
|
- }
|
|
|
|
|
|
-}
|
|
|
+ }
|
|
|
+}
|