Below one is used for get list of processes from the windows
Process proc = Runtime.getRuntime().exec (\"tasklist.exe\");
This is another aproach to parse the the process list from the command "ps -e":
try {
String line;
Process p = Runtime.getRuntime().exec("ps -e");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line); //<-- Parse data here.
}
input.close();
} catch (Exception err) {
err.printStackTrace();
}
If you are using Windows, then you should change the line: "Process p = Runtime.getRun..." etc... (3rd line), for one that looks like this:
Process p = Runtime.getRuntime().exec
(System.getenv("windir") +"\\system32\\"+"tasklist.exe");
Its not possible to get the application, because this are only the open windows shown on this tab. Every application is a process.
U could try this from c#:
var openWindowProcesses = System.Diagnostics.Process.GetProcesses()
.Where(p => p.MainWindowHandle != IntPtr.Zero && p.ProcessName != "explorer");
The openWindowProcesses should contains all open application which they have an active man window.
I put 'p.ProcessName != "explorer"' in the where expression because the explorer is the main process of the Desktop and it never should be closed.
To watching execution of the processes you can use "ManagementEventWatcher" class. See this please.