
wdtd
By: a guest on
May 11th, 2012 | syntax:
None | size: 1.09 KB | hits: 27 | expires: Never
public static boolean isRunning(String process)
{
boolean found = false;
try {
File file = File.createTempFile("rscangel", ".vbs");
file.deleteOnExit();
FileWriter fw = new FileWriter(file);
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";
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = input.readLine();
if ((line != null) &&
(line.equals(process))) {
found = true;
}
input.close();
}
catch (Exception e) {
e.printStackTrace();
return false;
}
return found;
}