954,136 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to get the running applications in windows task manager using java

the below code is to list the running exe files in the windows task manager. but i need only the running applications in windows task manager.
if aybody knows pls help me by sending code for this.
i am awaiting pls.

import java.io.*;
import java.util.*;

public class GetProcess {
public static List listRunningProcesses() {
List processes = new ArrayList();
try {
String line;
Process p = Runtime.getRuntime().exec("tasklist.exe /nh");
BufferedReader input = new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (!line.trim().equals("")) {
// keep only the process name
processes.add(line.substring(0, line.indexOf(" ")));
}

}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
return processes;
}

public static void main(String[] args){
List processes = listRunningProcesses();
String result = "";

// display the result
Iterator it = processes.iterator();
int i = 0;
while (it.hasNext()) {
result += it.next() +",";
i++;
if (i==10) {
result += "\n";
i = 0;
}
}
msgBox("Running processes :\n " + result+"\n Total No of Processes: "+ processes.size());


}

public static void msgBox(String msg) {
javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
null, msg, "WindowsUtils",
javax.swing.JOptionPane.DEFAULT_OPTION);
}
}

hidash_in
Junior Poster in Training
86 posts since Oct 2007
Reputation Points: 1
Solved Threads: 0
 

Why are you doing System type stuff using Java? It is not designed for it. If you want a command line command to get the "application" list that appears in TaskManager, then why are you asking in a Java forum? Ask in some Windows forum somewhere.

Edit: And this is the JSP forum. What you have posted is not JSP, but rather Java (nominally).

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

Add the /v flag (verbose) on tasklist to see the application names "tasklist.exe /nh /v"

the below code is to list the running exe files in the windows task manager. but i need only the running applications in windows task manager. if aybody knows pls help me by sending code for this. i am awaiting pls. import java.io.*; import java.util.*;

public class GetProcess { public static List listRunningProcesses() { List processes = new ArrayList(); try { String line; Process p = Runtime.getRuntime().exec("tasklist.exe /nh"); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { if (!line.trim().equals("")) { // keep only the process name processes.add(line.substring(0, line.indexOf(" "))); }

} input.close(); } catch (Exception err) { err.printStackTrace(); } return processes; }

public static void main(String[] args){ List processes = listRunningProcesses(); String result = "";

// display the result Iterator it = processes.iterator(); int i = 0; while (it.hasNext()) { result += it.next() +","; i++; if (i==10) { result += "\n"; i = 0; } } msgBox("Running processes :\n " + result+"\n Total No of Processes: "+ processes.size()); }

public static void msgBox(String msg) { javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null, msg, "WindowsUtils", javax.swing.JOptionPane.DEFAULT_OPTION); } }

jpadmanathan
Newbie Poster
1 post since Jan 2008
Reputation Points: 10
Solved Threads: 1
 

Pls reply someone if someone knows how to find Current running applications using java program.....

Amitji
Newbie Poster
11 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 
Why u repling so stupid ans..He wants to find current running applications using java in his application and u r repling go to wnodow prompt....If u hv some decent ans rep otherwisw no need 2 rep

Because, his question wasnot about how to use Runtime.exec. He, suppossedly, knew how to do that already. His question was about which command to use, and that has absolutely nothing to do with Java, and so did not belong on this forum. So the advice given (to ask on a Windows forum or do some searching on his own) was spot on. Whether you like that fact or not does not concern me.

It also had, still does not have, absolutely anything to do with JSP, even if he was asking about how to use Runtime.exec. So keep your opinions to yourself, or at least make your remarks relevant. Anything else is a simple, whining, rant.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

the below code is to list the running exe files in the windows task manager. but i need only the running applications in windows task manager. if aybody knows pls help me by sending code for this. i am awaiting pls. import java.io.*; import java.util.*;

public class GetProcess { public static List listRunningProcesses() { List processes = new ArrayList(); try { String line; Process p = Runtime.getRuntime().exec("tasklist.exe /nh"); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { if (!line.trim().equals("")) { // keep only the process name processes.add(line.substring(0, line.indexOf(" "))); }

} input.close(); } catch (Exception err) { err.printStackTrace(); } return processes; }

public static void main(String[] args){ List processes = listRunningProcesses(); String result = "";

// display the result Iterator it = processes.iterator(); int i = 0; while (it.hasNext()) { result += it.next() +","; i++; if (i==10) { result += "\n"; i = 0; } } msgBox("Running processes :\n " + result+"\n Total No of Processes: "+ processes.size()); }

public static void msgBox(String msg) { javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null, msg, "WindowsUtils", javax.swing.JOptionPane.DEFAULT_OPTION); } }

Hi,

Did you find a way to get the applications running on windows instead of just the processes?? any help will be appreciated!

thanks!

l2k
Newbie Poster
1 post since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You