public static boolean getProcess() {
boolean flag = false; try { Process p = Runtime.getRuntime().exec("cmd /c tasklist "); ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream os = p.getInputStream(); byte b[] = new byte[256]; while (os.read(b) > 0) baos.write(b); String s = baos.toString(); // System.out.println(s); if (s.indexOf("smss.exe ") >= 0) { System.out.println("yes "); flag = true; } else { System.out.println("no "); flag = false; } } catch (java.io.IOException ioe) { } return flag; } public static void main(String[] args) { if(getProcess()){ System.out.println("********* ok *********"); }else{ System.out.println("********* no *********"); } } |
|