Don't like ads? PRO users don't see any ads ;-)
Guest

wdtd

By: a guest on May 11th, 2012  |  syntax: None  |  size: 1.09 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.   public static boolean isRunning(String process)
  2.   {
  3.     boolean found = false;
  4.     try {
  5.       File file = File.createTempFile("rscangel", ".vbs");
  6.       file.deleteOnExit();
  7.       FileWriter fw = new FileWriter(file);
  8.  
  9.       String vbs = "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\nSet locator = CreateObject(\"WbemScripting.SWbemLocator\")\nSet service = locator.ConnectServer()\nSet processes = service.ExecQuery _\n (\"select name from Win32_Process where name='" + process + "'\")\n" + "For Each process in processes\n" + "wscript.echo process.Name \n" + "Next\n" + "Set WSHShell = Nothing\n";
  10.  
  11.       fw.write(vbs);
  12.       fw.close();
  13.       Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
  14.  
  15.       BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
  16.  
  17.       String line = input.readLine();
  18.       if ((line != null) &&
  19.         (line.equals(process))) {
  20.         found = true;
  21.       }
  22.  
  23.       input.close();
  24.     }
  25.     catch (Exception e) {
  26.       e.printStackTrace();
  27.       return false;
  28.     }
  29.     return found;
  30.   }