Right now this is what I have to get all currently running processes:
Process proc = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
List<String> lines = new ArrayList<String>();
String line;
while ((line = bufferedReader.readLine()) != null)
lines.add(line);
bufferedReader.close();
for (int i = 3; i < lines.size(); i++)
{
String name = lines.get(i);
name = name.substring(0, name.indexOf(" "));
if (!name.endsWith("exe") && name.contains("."))
name = name.substring(0, name.indexOf('.')) + ".exe";
System.out.println(name);
}
There's two problems with this: First, it's getting ALL the processes, I only want the processes with an open window. Second, the long process names get cut off somehow, and I don't know why that happens. So how can I get only the processes with an open window?