首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JAVA 检测历程 检查进程

2012-11-05 
JAVA 检测进程 检查进程import javax.swing.JOptionPanepublic class ProcessChecking {?? ??? private s

JAVA 检测进程 检查进程

import javax.swing.JOptionPane;


public class ProcessChecking {
??
??? private static int tasklist1 = -1;
??? public int checkProcess(String progressName){
??? ??? try {

??? ??? ??? String cmd = "cmd.exe /c? tasklist";
??? ??? ??? Process p = Runtime.getRuntime().exec(cmd);
??? ??? ??? StringBuffer out = new StringBuffer();
??? ??? ??? byte[] b = new byte[1024];
??? ??? ??? for (int n; (n = p.getInputStream().read(b)) != -1;) {
??? ??? ??? ??? out.append(new String(b, 0, n));
??? ??? ??? }
??? ??? ??? tasklist1 = out.toString().indexOf(progressName);// 检查QQ进程
??? ??? } catch (Exception e1) {
??? ??? ??? e1.printStackTrace();
??? ??? }

?

?



??? ??? if (tasklist1 == -1) {

??? ??? ??? //JOptionPane.showMessageDialog(null, "程序已经关闭!", "警告", 1);
??? ??? ??? return 0;
??? ??? } else {
??? ??? ??? //JOptionPane.showMessageDialog(null, "程序已经打开!", "警告", 1);
??? ??? ??? return 1;
??? ??? }
??? ???
??? }
???
}

?

?

?

?

要做一个web 远程开软件关软件,那么要判断这个软件的进程是不是启动着,所有要进程判断下

热点排行