command for obtaining the list of currently running applications on windows
I need to obtain the list of the currently running applications on windows using command or java program. for example if MS-Word and Window media player are the applications currently running on the system, then i want the list of these applications开发者_StackOverflow中文版 using a command or a java program.
Thanks and regards Vivek Birdi
For windows
WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid
Try executing this command from java that will list all currently running process on the file specified
Here is an example how to execute command from java
FYI:
for linux:
ps aux | less
Alternatively you can also use this ready made code for windows:
public static List<String> listRunningProcesses() {
List<String> processes = new ArrayList<String>();
try {
String line;
Process p = Runtime.getRuntime().exec("tasklist.exe /fo csv /nh");
BufferedReader input = new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (!line.trim().equals("")) {
// keep only the process name
line = line.substring(1);
processes.add(line.substring(0, line.indexOf(""")));
}
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
return processes;
}
source :http://www.rgagnon.com/javadetails/java-0593.html
精彩评论